HTML CSS training

Thursday, June 3, 2010

Last week we had training on HTML CSS taken by Lakshminarayana. Training included on-board explaination, theory lectures, Hands-On as well as assessment (which I have not completed till i wrote this post). I am going to put some of the points that I learnt and found really useful which as a developer we tend to ignore or forget.
Specificity : It shows that how specific a selector is and based on the weight-age it assigns the value. Specificity is calculated as follow :
if Specificity is --> a b c d
then a i shows if it is inline style. if yes (a=1) and the specificity becomes highest and gets precedence over all other selectors.
b shows number of Id attributes in the selector
c is for class and pseudo classes
d is for number of elements

Box Model

You can define margin as either explicitly margin-left, margin-top
or you can give it as whole
margin: '10px 12px 6 px 4px';
where 10px is top margin, 12 is right and sequentially clockwise.

Similarly padding and border can be defined.
margin backgrounds are always transparent.

In CSS 2.1 horizantal margin never collapse but vertical may.

Vertical margins may collapse between certain boxes:

  • Two or more adjoining vertical margins of block boxes in the normal flow collapse. The resulting margin width is the maximum of the adjoining margin widths. In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins. If there are no positive margins, the absolute maximum of the negative adjoining margins is deducted from zero. Note. Adjoining boxes may be generated by elements that are not related as siblings or ancestors.
  • Vertical margins between a floated box and any other box do not collapse (not even between a float and its in-flow children).
  • Vertical margins of elements that establish new block formatting contexts (such as floats and elements with 'overflow' other than 'visible') do not collapse with their in-flow children.
  • Margins of absolutely positioned boxes do not collapse (not even with their in-flow children).
  • Margins of inline-block elements do not collapse (not even with their in-flow children).
  • If the top and bottom margins of a box are adjoining, then it is possible for margins to collapse through it. In this case, the position of the element depends on its relationship with the other elements whose margins are being collapsed.
    • If the element's margins are collapsed with its parent's top margin, the top border edge of the box is defined to be the same as the parent's.
    • Otherwise, either the element's parent is not taking part in the margin collapsing, or only the parent's bottom margin is involved. The position of the element's top border edge is the same as it would have been if the element had a non-zero bottom border.

    An element that has had clearance applied to it never collapses its top margin with its parent block's bottom margin.

    Note that the positions of elements that have been collapsed through have no effect on the positions of the other elements with whose margins they are being collapsed; the top border edge position is only required for laying out descendants of these elements.

  • Margins of the root element's box do not collapse.
Margin width property can be difine in 2 ways, one through definite margin width and another is percentage. percentage value is defined based on width of the content (even margin-top also refers to width of content in case of percentage. so percentage of content's width is taken not the height)

0 comments: