Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra space before and after H1 tag

Tags:

html

css

Even after reseting margin and padding the h1 tag still has mysterious unwanted gaps before and after its content

see code pen

Adding

 line-height:0.7em;

rule approximately resolve the problem, however

  1. it looks unclean
  2. there are still few unwanted pixels
  3. not sure that this will not cause issues with different font size or units.

Is there a clean and universal solution, maybe using sass/less mixin with math operations?

HTML:

<h1>Some text</h1> 

CSS

* { margin:0;padding:0; }
h1 { font-size:25em; } 
like image 611
i am jack's wasted life Avatar asked Mar 09 '16 09:03

i am jack's wasted life


1 Answers

the h1 tag by default has line-heigth property you can adjust it like

h1 {
font-size: 25em;
line-height: 0.7em;
} 

updated example

* {
  margin:0;
  padding:0;
}
h1 {
  font-size:25em;
  line-height:0.7em;
}
<h1>Some text</h1>
<p>lorem ispum</p>
like image 111
Peter Wilson Avatar answered Sep 18 '22 05:09

Peter Wilson