Css Div不是浏览器的100%宽度

Css Div不是浏览器的100%宽度,css,html,Css,Html,我的div不会拉伸浏览器的整个宽度,它会在两端短停大约10px .header{ 位置:相对位置; 背景色:#088ed7; 宽度:自动; 高度:20px; } …可能是页面的边距和/或填充 加: html,正文{ 填充:0; 保证金:0; } .标题{ 保证金:0; } html, 身体{ 填充:0; 保证金:0; } .标题{ 保证金:0; 位置:相对位置; 背景色:#088ed7; 宽度:自动; 高度:20px; } …对于我的许多项目,我添加了以下重置css。那么,就没有问题了=)

我的div不会拉伸浏览器的整个宽度,它会在两端短停大约10px

.header{
位置:相对位置;
背景色:#088ed7;
宽度:自动;
高度:20px;
}

可能是页面的边距和/或填充

加:

html,正文{
填充:0;
保证金:0;
}
.标题{
保证金:0;
}
html,
身体{
填充:0;
保证金:0;
}
.标题{
保证金:0;
位置:相对位置;
背景色:#088ed7;
宽度:自动;
高度:20px;
}

对于我的许多项目,我添加了以下重置css。那么,就没有问题了=)

CSS

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
    background: transparent;
    border: 0;
    margin: 0;
    padding: 0;
    vertical-align: baseline;
}
body {
    line-height: 1;
}
h1, h2, h3, h4, h5, h6 {
    clear: both;
    font-weight: normal;
}
ol, ul {
    list-style: none;
}
blockquote {
    quotes: none;
}
blockquote:before, blockquote:after {
    content: '';
    content: none;
}
del {
    text-decoration: line-through;
}
/* tables still need 'cellspacing="0"' in the markup */
table {
    border-collapse: collapse;
    border-spacing: 0;
}
a img {
    border: none;
}

添加以下css规则:

body {
    margin:0px;
    padding:0px;
}

在代码中添加以下css,新的单位“vw”视口宽度用于设置元素到视图端口的宽度

 html,body{
    margin:0;
    padding:0;
 }
 .header{
    width:100vw;
 }
有关更多详细信息,请参阅以下链接:

请提供指向该页面的链接,最好是指向JSFIDLE的链接,以便我们查看您的页面代码。上面的代码无法阻止这种情况的发生,因此问题一定出在其他地方。在.header div上是否有填充或边距?或者,在其容器div上的填充或边距?可能在包含div或body标签上有填充。请以有意义的方式编辑答案。添加此编辑的说明。请分享您的评论以改进答案。我更改了您的答案。请查收