2

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>
j08691
  • 204,283
  • 31
  • 260
  • 272
Martijn
  • 109
  • 1
  • 2
  • 8
  • 1
    Welcome to StackOverflow! In order for us to help you with CSS, you will need to provide your existing CSS in addition to your HTML; we can't reproduce your problem without it. Please update your question so that it shows your CSS as well, thus forming a [**minimal, complete, and verifiable example**](http://stackoverflow.com/help/mcve). For further information, please refer to the help article regarding [**how to ask good questions**](http://stackoverflow.com/help/how-to-ask), and take the [**tour of the site**](http://stackoverflow.com/tour) :) – Obsidian Age Jul 04 '17 at 20:49

4 Answers4

1

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;
Andy Ray
  • 30,372
  • 14
  • 101
  • 138
0

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

body { padding: 0 }
aaguilera
  • 1,080
  • 10
  • 27
0

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>
RïshïKêsh Kümar
  • 4,734
  • 1
  • 24
  • 36
  • There is still some space between the top from which it is aligned and from the top of the highest letter. You can see it when you select the text. Sorry, but this is not the solution. – Martijn Jul 04 '17 at 21:31
  • It's Margin is zero , so how and where you see the space.. I can't believe .. okzz listen go and just google it for .. how to remove browser default css !! So you can easily understand what going on... And if you thik `line-height:0.8 is solution` then go for it.. – RïshïKêsh Kümar Jul 04 '17 at 22:15
  • Sorry .. but I don't thik it's right ans .. bcoz when you run the same code in different _different browser then you get the real difference .. between .. So best of luck.. happy to help.. I don't have any problem !! Thank you – RïshïKêsh Kümar Jul 04 '17 at 22:19
0

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.

rbnvrw
  • 347
  • 3
  • 15