0

I would like to have paragraph text right under the headline. I set margin and padding to 0 for both, but there is still small gap between them. Why? Thanks.

1
  • 2
    Please post your CSS and HTML so we can replicate Sep 22, 2010 at 14:44

3 Answers 3

1
line-height:1em;

also add a border for testing:

border:1px solid #f00;
1

It is from the line-height property of the headline.

Try it like this:

<h1 style="margin:0; padding:0; line-height:1em;">Heading</h1>
<p style="margin:0;">Paragraph</p>
0

Make sure that you remove the bottom padding and margin for the heading above and you should be set

<style>
.h2 { margin-bottom:0px; padding-bottom:0px; }
p { margin:0px; padding:0px 0px 15px 0px; }
</style>

I've added a padding-bottom to the paragraph tags so you can have separation between each <p> tag.

1
  • Don't put a global P margin like that, it will affect all P tags. Instead focus on a rule for that particular paragraph, or use selectors to select the next element. See where this can become tricky?
    – jcolebrand
    Sep 22, 2010 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.