当保证金设置为自动时,如何将div的左侧分配到屏幕的左侧?

时间:2015-10-06 05:28:13

标签: html css screen center element

例如我创建了一个像这样的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),如何消除div左边和屏幕左边之间的间隙?

由于

3 个答案:

答案 0 :(得分:2)

你很可能仍然需要更新你的html和body css。

html,body {
  margin: 0;
  padding: 0;
}

答案 1 :(得分:1)

使用像

这样的基本CSS
*{margin:0; padding:0;}

答案 2 :(得分: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;
}