1

Possible Duplicate:
CSS selector for “foo that contains bar”?

All the <p> on my site get margin-bottom of 20px.

I don't want to apply this margin-bottom to <p> which contain an <em> element.

Is it possible to this without classes or id's.

CSS3 can be used.

Community
  • 1
  • 1
Hedge
  • 13,498
  • 35
  • 122
  • 223

6 Answers6

2

I'm afraid this isn't possible with pure CSS.

PeeHaa
  • 66,697
  • 53
  • 182
  • 254
1

Unfortunately, there is no way to do this with pure css. See Is there a CSS parent selector?

You could use some jQuery though.

$('em').parent().css('marginBottom','0');

http://jsfiddle.net/jasongennaro/5pPGF/

Community
  • 1
  • 1
Jason Gennaro
  • 32,917
  • 6
  • 59
  • 84
1

The only way I could see doing this in pure CSS is with a parent-node selector. Unfortunately, such a thing does not exist in CSS2 or CSS3.

Community
  • 1
  • 1
aroth
  • 51,522
  • 20
  • 132
  • 168
1

What you're describing is basically an "ascendent" selector, selecting some element based upon its descendents. This isn't possible using just CSS, you would have to also use JavaScript.

dbb
  • 1,030
  • 6
  • 12
1

Pure CSS does not do that (yet) as far as I know, but you can achieve this by smart use of jQuery:

$(function() {
    $("em").parent("p").addClass("nomargin")
})

Or something like that...

Roland Tepp
  • 7,673
  • 10
  • 53
  • 68
0

Your question is unclear. Pleae recheck your question. But you can set margins, paddings for global tags like

p{margin:0}

or

*{margin:0; padding:0 } for all elements then change it for exact divs, classes. In that case all other ones still will set to margin:0, padding:0

Tural Ali
  • 19,346
  • 18
  • 69
  • 127