CSS In Depth
reviewing the fundamental
cascade,specificity and inheritance
cascede
keep selector under conrtol
- stylesheep origin
- user agent style
- author
- author important
- specificity
- inline-style(HTML)
- selector specificity
selector | IDs | classed | tags | notation |
---|---|---|---|---|
html body header h1 | 0 | 0 | 4 | 0,0,4 |
#page-title | 1 | 0 | 0 | 1,0,0 |
- source order(CSS)
inherit,initial(hard-reset)
Don’t confuse cascade with inheritance
shortand properities
Stay out of trouble with shortand properies
Working with relative units
Tip:use rems for font-size,pixels for borders,and ems for most other properties
em,rem
1 | .padded{ |
viewport-relative
- viewport-relative
- vh:1/100th of the viewport height
- vw:1/100th of the viewport width
- vmin:1/100th of the smaller dimemsion,height or width
- vmax
custom properties(aka css variables)
1 | :root{ |
unitless valus
use unitless valus when specifying line height
1 | body{ |
mastering the box model
1 | :root{ |
nerver explicitly set the height of an element
difficuties with element height,columns of equal height
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18.wrapper{
margin-left: -1.5em;
margin-right: -1.5em;
}
.container{
display:table;
width:100%;
/* margin can't work */
border-spacing:1.5em 0;
}
.main{
display: table-cell;
width:70%;
}
.sidebar{
display: table-cell;
width:30%;
}
- how to center
- table-cell,vertical-align
- flex
- absulute positioning
- line-height
collapsed margin
margin collapsing only occurs with top and bottom
- collapsing between text
- collapsing multiple margin
- collapsing ouside a container
mastering layout
mastering float
Tip: By using max-width instead of width to avoid horizontal scrolling on the devies with smaller screens.
clear float
1 | .clear{ |
Establishing a block formatting context
it isolates its contents from the outside context)
- BFC Page:103
- float:left,float:right
- overflow:hidden,auto,scroll,
- display:inline-block
- position: absolute or fixed