Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting globals in html or body

Tags:

html

css

I have some questions regarding the following css that I found:

html, body {
    height:100%;
    min-width:100%;
    position:absolute;
}

html {
    background: none repeat scroll 0 0 #fff;
    color:#fff;
    font-family:arial,helvetica,sans-serif;
    font-size:15px;
}


  1. is it necessary to have height and min-width to 100% on the html and body? What's the benefit?
  2. what is the reason for using position absolute?
  3. why did they set the background/color/font on the html and not the body? Is there a difference? Or is it just preference?


like image 410
paul smith Avatar asked Jun 12 '12 00:06

paul smith


People also ask

What is global in HTML?

The global attributes are attributes that can be used with all HTML elements. Attribute. Description. accesskey. Specifies a shortcut key to activate/focus an element.

Is class a global attribute in HTML?

The class global attribute is a space-separated list of the case-sensitive classes of the element. Classes allow CSS and JavaScript to select and access specific elements via the class selectors or functions like the DOM method document. getElementsByClassName .

Is ID a global attribute in HTML?

The id attribute is a Global Attribute, and can be used on any HTML element.

What is body in HTML?

The <body> element contains all the contents of an HTML document, such as headings, paragraphs, images, hyperlinks, tables, lists, etc. Note: There can only be one <body> element in an HTML document.


2 Answers

  1. It's usually unnecessary. However, there are a few times where you may need it. For example, maybe your base/site-wide website css file specifies the size to be different (you know those sites where the sides are just borders, usually blogs? Those widths have been resized down). Note that when you have percent it's of the parent container. So Div A may have width: 100% but if it's parent container has width: 500px Div A will have 100% of 500px.

  2. There is no reason for position: absolute on the html + body that I can think of. One side effect of absolute positioning is that the element nolonger "floats inline" with the rest of the elements (not sure how you would describe/word this).

    For example, position: relative ignores absolutely positioned elements. So if you had Image A (absolute) and Image B (relative) and B had left: 10px;, Image B would be offset from the left of the parent, instead of where A would have been. Hopefully I'm making sense here.

    So sometimes I just set "position: absolute" whenever I have a background image. If it's the first child, it everything will show up on top of it (since the new elements are "added on top" and ignore the absolute-positioned element).

  3. The body will inherit those properties, and so yes it's just preference.

like image 117
Raekye Avatar answered Sep 24 '22 11:09

Raekye


Setting the width or height of an element to 100% only works when its parent element is also at 100% of that dimension. Which means that if the body or even html tag isn't, for some reason, at 100% of either height or width, an element inside it with those properties will have 0 height or width.

For example: http://jsfiddle.net/KZaum/

like image 26
mowwwalker Avatar answered Sep 25 '22 11:09

mowwwalker