当边距设置为自动时,如何将div的左侧分配给屏幕左侧?
例如,我创造了这样当边距设置为自动时,如何将div的左侧分配给屏幕左侧?
<div class="baseDiv" ></div>
和CSS代码一个div是:
.baseDiv {
margin:0 auto 0 auto;
display:block;
margin-top:-10px;
width: 100%;
height:150px;
background-color:#039;
}
我定格到页面的中心和左格适合屏幕左侧,但还有一定的差距(约20px),如何消除div左边和屏幕左边之间的空隙?
谢谢
你最有可能仍然需要更新你的html和body css。
html,body {
margin: 0;
padding: 0;
}
谢谢@ partypete25 – MojtabaSh
没有问题。大多数浏览器的边距都是8px。这很可能是这里的问题。为了确保我已经将html添加到选择器,并且指定的填充也设置为0。 使用通用选择器(*)适用于页面上的所有元素。 – partypete25
对不起,只是我没有看到你的答案,所以我接受@Shailesh Patel答案,再次感谢 – MojtabaSh
有你开始你的CSS的CSS重置每次和你会避免很多这样类似的问题:http://meyerweb.com/eric/tools/css/reset/
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
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, 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,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
检查填充 –
填充唐没有工作:/ – MojtabaSh
如果您的宽度为100%,margin 0 auto就没有意义; –