Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line-Height VS Padding in Nav (Correct Method)

Tags:

html

css

padding

I am just getting back into coding and I would like to know what is the best method for adding heigh to my btn.

Here is the code -

Padding method

.nav-main li a {
  display: block;
  padding: 70px 10px 70px 10px;
  color: #6CF784;
  border-bottom: 10px solid white;
  text-decoration: none; 
}

Line-height method

.nav-main li a {
  display: block;
  padding: 0 10px 0 10px;
  line-height: 150px;
  color: #6CF784;
  border-bottom: 10px solid white;
  text-decoration: none; 
}
like image 492
Stephen Mottershead Avatar asked Feb 04 '14 11:02

Stephen Mottershead


People also ask

Should I use padding or height?

Yes, it is wrong to use padding to control the element height. height controls the actual height of the element (basically the distance from border-bottom to border-top ) whereas padding controls the distance between the content and the border.

What is the difference between line height and padding?

I personally use padding as it gives me more control across browsers, as line height can vary on which font you are using, along with what fonts are installed/not installed on the clients' browser. Save this answer.

When should I set my line height?

The line-height CSS property sets the height of a line box. It's commonly used to set the distance between lines of text. On block-level elements, it specifies the minimum height of line boxes within the element. On non-replaced inline elements, it specifies the height that is used to calculate line box height.

Should I use padding or margin?

In general, use margins when you're adjusting the spacing of an element in relation to another element (i.e a div in relation to another div on the page), and padding when you're adjusting the look of an individual element (i.e the amount of pixels between the edge of a div and the text within it).


1 Answers

I like to use line-height because it positions the baseline correctly to make the text appear in the middle of the element (whereas with padding it may be off-centre one way or the other based on the font)

Of course, this relies on you using a pixel value for line-height (as you are doing in your question) - using a numeric value like 1.5 may produce different results depending on the font.

like image 71
Niet the Dark Absol Avatar answered Sep 23 '22 06:09

Niet the Dark Absol