0

对不起标题。真的不知道该说什么。在这里解释更容易。

基本上我想要一个具有相对位置的标题,稍后我将在其中放置一个导航菜单。我希望它是 100% 宽(因此它覆盖整个页面)和大约 130px 高。我的问题是即使设置为 100% 宽,左侧也有一点空间。html/body 也是如此。在标题的右侧没有空格。我希望它居中。

这是我的代码:

html, body {
    font-family: Tahoma, Geneva, sans-serif;
    font-size: 12px; 
    -webkit-font-smoothing: antialiased; 
    font-smoothing: antialiased;
    height: 100%;
    width: 100%;
    overflow: hidden;
}
#header {       
    -webkit-box-shadow: 0px 0px 30px #7a7a7a; 
       -moz-box-shadow: 0px 0px 30px #7a7a7a; 
            box-shadow: 0px 0px 30px #7a7a7a;
    width: 100%;
    height: 130px;
    margin-right: auto;
    margin-left: auto;
    background-color: #fff;
    position: relative;
}
4

2 回答 2

2

将元素的 设置为 0 marginbody

于 2013-02-03T13:47:09.017 回答
0

当你不应用一些预定义的 CSS 规则时,它基本上会发生。为什么预定义是因为一些浏览器呈现自己的样式,比如边距应该是 1px 等,所以你必须用你自己的 CSS 规则覆盖它。是的,Levi Botelho 给出你是正确的答案。只要你要在 css 的帮助下描述 html 内容,只需包含以下规则。

/**
 * 1.0 Reset
 *
 * Modified from Normalize.css to provide cross-browser consistency and a smart
 * default styling of HTML elements.
 *
 * @see http://git.io/normalize
 * ----------------------------------------------------------------------------
 */

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, i, center, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, audio, canvas, details, figcaption,
figure, footer, header, hgroup, mark, menu, meter, nav,
output, progress, section, summary, time, video {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    font-size: 100%;
    vertical-align: baseline;
    background: transparent;
}

body {
    line-height: 1;
}

article, aside, dialog, figure, footer, header, 
hgroup, nav, section, blockquote { 
    display: block;
}

nav ul {
    list-style: none;
}

ol {
    list-style: decimal;
}

ul {
    list-style: disc;
}

ul ul {
    list-style: circle;
}

blockquote, q {
    quotes: none;
}

blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}

ins {
    text-decoration: underline;
}

del {
    text-decoration: line-through;
}

mark {
    background: none;
}

abbr[title], dfn[title] {
    border-bottom:1px dotted #000;
    cursor:help;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

hr {
    display: block;
    height: 1px;
    border: 0;  
    border-top: 1px solid #ccc;
    margin: 1em 0;
    padding: 0;
}

input[type="submit"], input[type="button"], button {
    padding: 0 !important;
    margin: 0 !important;
}

input, select, a img {
    vertical-align: middle;
}



/*
--------------------------------------------------------------------
            End of reset css properties
--------------------------------------------------------------------
 */

希望得到答案!

于 2013-12-29T11:01:17.520 回答