I. EM and REM
When it comes to adaptive layouts, you have to mention REM as a unit.
To put it simply
- em: is the font size, depending on the element's own font size, if it does not define the font size, then inherit the parent element's font size, that is, 1em = 1 font-size;
- REM: Similar to EM, can be seen as Root-em, is based on the root element of the font size to define, that is, the HTML set font size to define, the default HTML font size is 16px;
Use a demo to illustrate the best:
<style>HTML{font-size:50px;}#wrapper{font-size:40px;Background-color:Red;width:2em;Height:2em; }#outter{font-size:20px;Background-color:Yellow;width:2em;Height:2em; }#inner{font-size:10px;background:Blue;width:2em;Height:2em; }#wrapper-1{font-size:40px;Background-color:Red;width:2rem;Height:2rem; }#outter-1{font-size:20px;Background-color:Yellow;width:2rem;Height:2rem; }#inner-1{font-size:10px;background:Blue;width:2rem;Height:2rem; }</style><Body> <DivID= ' wrapper '> <DivID= ' Outter '> <DivID= ' inner '>0</Div> </Div> </Div> <DivID= ' wrapper-1 '> <DivID= ' outter-1 '> <DivID= ' inner-1 '>1</Div> </Div> </Div></Body>
The result, on the use of EM, for REM
It can be seen that the size of EM varies according to the size of its own elements, while REM does not, and has always been the font-size of the root.
Second, width and height
I want to get the width of the above elements, I used to use:
// The result is ""
Find the information and find that this is used to find the properties of CSS elements set, and generally should use the following methods:
1.clientWidth and ClientHeight
var width = el.clientwidth; var height = el.clienheight;
Description: Padding and scroll changes, only change
2.scrollWidth and Box.scrollheight
var width = el.scrollwidth; var height = el.scrollheight;
Description, 1) border changes, different browsers have different changes 2) padding change, change 3) margin change, no change
3.offsetWidth and Offsetheight
var width = el.offsetwidth; var height = el.offsetheight;
shows that padding and border are changed.
CSS units, Em,rem, and the width and height of elements