0

我有一个 div

<div id="cpyright" class="copyright" >
</div>

.copyright {
    float: right;
    margin-right: -115px;
    margin-top: -20px;
}

这种风格在火狐浏览器中得到应用。但在 chrome 中,div 位置是中心。为什么会这样。任何帮助,将不胜感激。

4

1 回答 1

0

在某些情况下,不同浏览器中的不同定位是由于每个浏览器都有一些默认的 CSS 元素样式。例如正文的边距。CSS Reset最佳做法是使用可用的代码模板之一(谷歌)重置您的 CSS 。

这是Eric 的一个例子

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0b1 | 201101 
   NOTE: WORK IN PROGRESS
   USE WITH CAUTION AND TEST WITH ABANDON */

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, figcaption, figure, 
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    outline: 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;
}

/* remember to define visible focus styles! 
:focus {
    outline: ?????;
} */

/* remember to highlight inserts somehow! */
ins {
    text-decoration: none;
}
del {
    text-decoration: line-through;
}

table {
    border-collapse: collapse;
    border-spacing: 0;
}

对于您的情况,您可能希望将 divabsolute放在bottom right角落里。这是正确的方法。

.copyright {
    position: absolute;
    right: 0;
    bottom: 20px;
}

position:fixed;即使用户向下滚动页面,您也可以使用它,div它将保持在该固定位置。

于 2013-06-02T07:23:21.667 回答