August 21, 2010

CSS Selector for Absence of Tag

Question by Ethan Turkeltaub

Given this HTML:

<div class="entry">
    <a class="meta">Aug. 20, 2010</a>
    <div class="content">
        <h2><a href="#">Hello.</a></h2>
        <p>...</p>
    </div>
</div>
<div class="entry">
    <a class="meta">Aug. 20, 2010</a>
    <div class="content">
        <p>...</p>
    </div>
</div>

And this CSS:

.entry{
    width: 760px;
}

.entry .meta{
    float: left
    width: 160px;
}

.entry .content{
    float: right;
    width: 600px;
}

Is there a selector to add a margin-top: 25px; to .entry .meta in the absence of the <h2> tag? Or will I need to resort to JavaScript for this?

Answer by Starx

Try this

.content > h2+p { margin:1px; }
.content > p { margin-top:25px; }

See Demo

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!