当边距设置为自动时,如何将 div 的左侧分配给屏幕左侧?
how can assign left of div to left of screen when margin set to auto?
例如我创建了一个像这样的div
<div class="baseDiv" ></div>
和css代码是:
.baseDiv {
margin:0 auto 0 auto;
display:block;
margin-top:-10px;
width: 100%;
height:150px;
background-color:#039;
}
我将div设置为页面中心,div左侧适合屏幕左侧,但每次都有一个间隙(约20px),如何消除[=左侧之间的间隙22=] 和屏幕左侧?
谢谢
您很可能还需要更新您的 html 和正文 css。
html,body {
margin: 0;
padding: 0;
}
像
一样使用基本的css
*{margin:0; padding:0;}
每次从 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;
}
例如我创建了一个像这样的div
<div class="baseDiv" ></div>
和css代码是:
.baseDiv {
margin:0 auto 0 auto;
display:block;
margin-top:-10px;
width: 100%;
height:150px;
background-color:#039;
}
我将div设置为页面中心,div左侧适合屏幕左侧,但每次都有一个间隙(约20px),如何消除[=左侧之间的间隙22=] 和屏幕左侧?
谢谢
您很可能还需要更新您的 html 和正文 css。
html,body {
margin: 0;
padding: 0;
}
像
一样使用基本的css*{margin:0; padding:0;}
每次从 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;
}