0

I have this piece of HTML.

<div class="page-top">
    <div class="page-title">
        <h2></h2>
        <h1></h1>
    </div>
    <div class="page-controls buttons">
        <a href="" class="button"></a>
   </div>
</div>

With two different styles for the h1. One where I apply a padding-top to the h1 when it's show alone. And the other style, for when the h1 is preceded by an h2, I remove the padding-top with .page-title h2 + h1

My question is how would you select the page-controls.buttons, only when the h1 is preceded by the h2. Is it possible?

andrantis
  • 70
  • 1
  • 1
  • 4

1 Answers1

1

Here's a solution with restructured markup: http://jsfiddle.net/functionalcss/k8dzg5zm/.

HTML:

<div class="page-top">
    <h2>Smaller Heading</h2>
    <h1>Big Heading</h1>
    <div class="page-controls buttons">
        <a href="" class="button">Click me</a>
    </div>
</div>

CSS:

.page-top > h2 +  h1 + .page-controls.buttons {
    background-color: yellow;
}
DRD
  • 5,557
  • 14
  • 14
  • Thank you. Your solution worked. Although I decided to give position absolute to one of the elements and accomplish what I needed. – andrantis Aug 07 '14 at 03:08