div位置在chrome和firefox上有所不同

时间:2013-06-02 06:50:22

标签: html

我有一个div

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

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

此样式将在firefox浏览器中应用。但在镀铬中,div位置是中心。为什么会发生这种情况。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

在必然情况下,不同浏览器中的不同定位是由于每个浏览器都有一些默认的CSS样式。例如身体的边缘。最佳做法是使用CSS Reset代码模板(Google for it)重置您的CSS。

这里是an example by 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;
}

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

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

此外,您可以使用position:fixed;,因此即使用户向下滚动页面,div也会保留在该固定位置。