2013-06-02 32 views
0

我有一個div格位置的不同之處Chrome和Firefox

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

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

這種風格被在Firefox瀏覽器被應用。但在鉻分區位置是中心。爲什麼會這樣呢?任何幫助,將不勝感激。

+3

'-115px','-20px'髒定位,您想如何精確對齊您的'div'?右側左側中心是什麼? –

+0

我不知道你是如何得到這些數字的,但是重置'body'的'margin'和'padding'聞起來很不錯:'body {margin:0;填充:0; }'。 – 2013-06-02 07:00:19

+0

我想把div放在右下角。 – user2444620

回答

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; 
} 

對於你的情況,你可能想在bottom right角落來定位DIV absolute光年。這是正確的做法。你

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

也可以使用position:fixed;這樣即使用戶向下滾動頁面時,div將保持在那個固定的位置。

+0

感謝它爲我工作。 – user2444620

相關問題