Martijn
Martijn

Reputation: 119

Remove white space at the top and the bottom in h3

h3 with white space at the top and the bottom

enter image description here

I have some white space around my h3. To align it the same as some pictures I want to delete the white space at the top and the bottom of the h3. The margin is 0, but there is still space between the top and the bottom of the text. How do I solve this?

this is my code:

<html>
 <head>
 </head>
 <body>
  <h3>title</h3>
 </body>
</html>

Upvotes: 3

Views: 4624

Answers (4)

Just Remove The Browser Default Margin and Padding Apply Top Of Your Css.

<style>

* {
  margin: 0;
  padding: 0;
}

</style>

NOTE:

  • Try to Reset all the html elements before writing your css.

OR [ Use In Your Case ]

<style>

  *{
        margin: 0px;
        padding: 0px;
    }

h3 {
        margin-top: 0px;
    }

</style>

DEMO:

<style>

  *{
        margin: 0px;
        padding: 0px;
    }

h3 {
        margin-top: 0px;
    }

</style>
<html>
 <head>
 </head>
 <body>
  <h3>title</h3>
 </body>
</html>

Upvotes: 0

rbnvrw
rbnvrw

Reputation: 402

As noted before, it is hard to reproduce your situation without the full CSS code that you have also.

However, a quick test of this gave me a h3 without any whitespace:

<html>
 <head>
 </head>
 <body style="padding: 0;">    
  <h3 style="margin: 0; padding: 0;">test</h3>
 </body>
</html>

It is probably browser dependent what the default margins/paddings on both the body and h3 elements are. I hope this helps you.

Upvotes: 0

aaguilera
aaguilera

Reputation: 1140

Remove the padding of the container element (in your example, the <body> tag):

body { padding: 0 }

Upvotes: 0

Andy Ray
Andy Ray

Reputation: 32066

You're confused about what the whitespace is. It's the full line height of the text, which accounts for potential above and below text characters, like accents and dangling letters. If you want to squish this whitespace (not recommended), set the line height to something smaller than the default, like

line-height: 0.8em;

Upvotes: 2

Related Questions