Mar 28, 2014

Which is the best unit for css line-height?

The line-height that is that many people overlook most people would know that we should not set the line-height, using an absolute or px because of its size, will not change the font-size so we. should be turned to the relative em units instead, but some people may not know that this method is not the best way.

Do not set the line-height with the Absolute.

So as not to waste time. We see examples do better. Let us do a simple archive of articles html code will look something like this.
Next, we put the css code below into it. Then try the Reviews
Css code, we set the line-height. .column1 with the px .column2 , we will use em when I try to get results of this review.
line-height_px_vs_em@1em
We see that both methods. The same results were okay This is because the value of 1.5em 24px enough, but what happens if one day we must come to the work by changing the font-size from 1em 2em.
When I preview again. We will not pass this resultant.
line-height_px_vs_em@2em
We will find it .column1 using the unit px is a part. .column2 used em's remains display beautifully intact because the line-height is set with px, then its size is fixed is to be 24px and not adjustable. font-size changes according to the line-height that is determined by its size is a multiple of em font-size itself, which in this case it is 1.5 times or 2em 48px enough.

Inheritance Em's problems

Now let's look at another example. Let us create a new page and insert the html code below to.
Then we put this css code into.
Css code above, we will compare the difference between the set line-height is not put em on the unit at all. Look how it's different, right? Let us take a review
line-height_em_vs_unitless@1em
The result is a With the same two columns Let us try to add css rule to another, we would add. font-size: 2em into the " article p "css code will become like this.
Before trying the Reviews Let us try to make the knowledge em's then imagine that the results would look like. When I try to answer the review yet.
line-height_em_vs_unitless@2em
We will find it .column1 used em is the problem. .column2 not wearing what unit Back rendered beautifully intact. Why is this?

Set line-height without the unit.

This is because determining the line-height with em, it will lead to. "Descendant (offspring)" That's it! It's bad huh? It will not solve Then have the children with me?
It sounds good But the problem is that the inheritance of the children, it was not to 1.5em but it is 16 × 1.5 = 24px separately for this reason. Although we are going to assign to article p has a 2em font-size and line-height, but it will still have the same size to 24px.
This problem was solved by determining the line-height form, do not enter any units. It allows the children to get to the "multiplier" or in this case 1.5 that just dealing with typography in the line-height, it is not difficult anymore.

No comments:

Post a Comment