核心提示:!DOCTYPE htmlhtmlheadmeta charset=UTF-8title/titlestyle type=text/css*{margin: 0px; padding: 0px;} ....
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ margin: 0px; padding: 0px; } .wrap{ width: 100%; } header{ background: black; height: 200px; //本来header可以继承父级wrap的宽度,如果加了absolute 或者fixed就不能继承父级的宽度,因为脱离 //当前文本流 /*position: fixed*/ /*position: absolute;*/ } </style> </head> <body> <p class="wrap"> <header> </header> </p> </body> </html>
一般block属性会自动继承父级的宽度,但是如果用了position :fixed (相对浏览器窗口定位)或者position:absolute,就不能继承父级的宽度,因为此时脱离了当前文档流,就应该设置宽度