开发者

Do I need to specify body, html at the top of my CSS?

I have been using the following at the top of every page.

body, html {
    color: #333333;
    font-family: Arial,sans-serif;
    font-size: 0.95em;
    line-height:开发者_运维百科 1.15;
}

But my workmate tells me I don't need both body and html.

Is this correct?


No you don't, you can omit html. All visible and presentational content to be formatted and styled with css will (and should) be within the <body> tag.


For the code above, you really don't need to style both html and body

However, some browsers apply margin and padding to one or the other, so it is a good practice to reset both

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

This helps especially if you are trying to place elements against the top/bottom of the browser window.


If you're dealing with margin, width or height and perhaps background you may need to target both, but for general properties, you don't. The properties you list here are fine on just body.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜