2011-03-10 82 views
1

我得到了一個額外的超簡單的HTML頁面與一個圖像作爲唯一的內容:爲什麼圖像不放在html頁面的最左上角?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Anzeige</title> 
</head> 
<body> 
     <img alt="Anzeige" src="images/image.gif" /> 
</body> 
</html> 

在Safari和Firefox(以及在UIWebView的,這是我原來的問題)的圖像沒有在顯示左上角,但有一個約5像素的小白色邊緣。當我單獨將圖像加載到Firefox中時,它是一樣的,但使用Safari和UIWebView時,它的最左上角沒有顯示邊框。

任何想法?

回答

5

這聽起來像你在談論的默認頁邊距。添加CSS:

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

您需要在瀏覽器的默認填充和利潤重置爲0使用:

http://meyerweb.com/eric/tools/css/reset/

它是如何工作是所有瀏覽器都默認填充和利潤實現的,並補充說,以你的CSS文件,它會重置所有瀏覽器邊距和填充爲0px。

此代碼將覆蓋你將永遠都瀏覽器的默認程序:

/* 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; 
} 
+0

究竟!將body和* margin/paddings設置爲零(0) – Tobias 2011-03-10 14:29:31

+0

@Tobiask不鼓勵使用'*',因爲它是瀏覽器密集型的,因此Eric Mayers是一種更有效的方法。 – 2011-03-10 14:31:48

相關問題