Web Design Forum: CSS problem with paragraphs and headings - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CSS problem with paragraphs and headings Modding a wordpress theme

#1 User is offline   MsCrow 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 18
  • Joined: 30-May 08
  • Reputation: 0
  • Experience:Nothing
  • Area of Expertise:Designer

Posted 16 March 2010 - 04:16 PM

Hello

I've been modding a theme for a test site (http://www.test1.com...diotoolkit.net/) and it's going ok except for a couple of basic things. The headings and paragraphs are all close together. This applies especially to paragraphs where there's little differentiation between them. I'd be grateful if someone could look at this. I've attached a screen shot of what I'm seeing.

I can attach the css if you have trouble accessing it.

Ellie

Attached File(s)


0

#2 User is offline   Wickham 

  • Web Guru
  • View gallery
  • Group: Moderators
  • Posts: 2,682
  • Joined: 11-June 09
  • Reputation: 233
  • Gender:Male
  • Location:Salisbury UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 16 March 2010 - 04:43 PM

You can edit the default margins and padding for h1 to h6 and p tags:-

h1 { margin: 0; padding: 8px 0; }
p { margin: 0; padding: 4px 0; }


which will make top & bottom the stated px and sides 0px; edit to what you want.

Or padding: 8px 0 4px 0; which is top right, bottom, left.
0

#3 User is offline   jnicol 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 52
  • Joined: 15-March 10
  • Reputation: 0
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 08:20 PM

Just to elaborate on what Wickham said, the reason the paragraphs have no margin on them is because of this global reset rule:

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

#4 User is offline   MsCrow 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 18
  • Joined: 30-May 08
  • Reputation: 0
  • Experience:Nothing
  • Area of Expertise:Designer

Posted 17 March 2010 - 08:51 AM

Thank you, I might get rid of the global reset (I wasn't sure that was it) first. If it sends the design a bit wonky then I'll try Wickham's solution. If you've got any feedback on the design I'd be grateful. I'm trying to get the most comfortable fonts with a modern design. If you look at http://www.communityradiotoolkit.net you'll see what I'm replacing.
0

#5 User is offline   jnicol 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 52
  • Joined: 15-March 10
  • Reputation: 0
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 17 March 2010 - 08:23 PM

I've nothing against global resets - I use Eric Myer's:

http://meyerweb.com/...reset-reloaded/

I only mentioned it in case you weren't aware why your margins were disappearing in the first place. A global reset is very useful, because my default there are padding, margin, and other styles applied to many HTML elements, and you will waste a lot of time creating CSS rules to overwrite them. It's faster, and gives you more control, to add styles only to the elements that need them.

To reset the paragraph margins to their default I would do as Wickham suggested, except my rule would be:

p {
margin:1.12em 0;
}

You might find this W3C page useful, it lists the defaults for all html elements:

http://www.w3.org/TR/CSS2/sample.html
0

#6 User is offline   Wickham 

  • Web Guru
  • View gallery
  • Group: Moderators
  • Posts: 2,682
  • Joined: 11-June 09
  • Reputation: 233
  • Gender:Male
  • Location:Salisbury UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 17 March 2010 - 08:33 PM

There is a strange effect called margin collapse as described here:-
http://www.howtocrea...argincollapsing
so it's often better to make margins 0 and use padding for h1 to h6 an p tags.

One effect is often that a heading or p tag right at the top of a div box will have the margin extended out of the top of the box, pushing it down while the text is right at the top of the box but its margin is outside. A background for the box will therefore be lowered while the text is right at the top. You'll recognise the problem when you meet it!
0

#7 User is offline   jnicol 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 52
  • Joined: 15-March 10
  • Reputation: 0
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 18 March 2010 - 12:36 AM

View PostWickham, on 17 March 2010 - 08:33 PM, said:

There is a strange effect called margin collapse


I agree that collapsing margins can be confusing, but most of the time they create the desired result. For a long time I would only apply margins to the bottom of paragraphs and headings to avoid collapsing margins, but more recently I've started to embrace the collapse. The article you linked to has some good tips for working around some of the quirks arising from collapsing margins.

Different strokes for different folks! :)

View PostWickham, on 17 March 2010 - 08:33 PM, said:

it's often better to make margins 0 and use padding for h1 to h6 an p tags.


Personally I wouldn't use padding as a substitute for margin, because they serve quite different purposes. e.g. If you want a padded colored background background on your headings AND a margin below them, then you are going to need to use both padding and margin to achieve the effect:

h2 {
background:#ff0000;
padding:10px;
margin:1em 0;
}
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users