1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

please help

Discussion in 'CSS' started by V-B, Aug 3, 2012.

  1. #1
    Hello there,

    I have this rule:

    .class1 {padding-bottom: 1em;}

    now I want to use <p> element under class1 attribute in a way that the declaration value (1em) of the class1 selector changes to (0.5em).

    Example:

    <div class="class1">

    <p>
    text content
    </p>

    <p>
    text content
    </p>

    <p>
    text content
    </p>

    <div>

    Now I want padding-bottom of <div> to become 0.5em instead of 1em when the code ends with </p>, without affecting the margins between the other <p> elements.

    Hope you got what I mean
     
    Last edited: Aug 3, 2012
    V-B, Aug 3, 2012 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    I would... lose the padding on the DIV, use padding instead of margins on P (so as to have no collapse issues), then use a negative margin on the bottom of the div equal to the bottom padding on the P minus 0.5em.

    As a rule of thumb I kill margins on P and use padding instead. If you want 0.5em all-around and 1em between P, padding:0.5em; is much cleaner than playing any margin tricks/games... or just set padding on the bottom only which is what I do on 99% of my pages. padding:0 0 1em; is often far easier to deal with than keeping track of margin collapse.

    Are you using the defaults for P, or are you using custom spacing? If I could see a bit more of your CSS I could probably dial in a solution better.
     
    deathshadow, Aug 3, 2012 IP
  3. MarkoJ

    MarkoJ Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Just add another class to only affect paragraph elements within that class, so:
    .class1 {padding-bottom: 1em;}
    p.class1 {padding-bottom: .5em;}

    Now everything in the class that is in paragraph tags will have a padding of .5, everything else will have a padding of .1.
    I believe that's what your asking.
     
    MarkoJ, Aug 5, 2012 IP