1

I want to style only the first .mask div, but I can't find how to do that (besides giving another class and style it). Is there a way using a pseudo-element such as :first-child or :first-of-type?

I have this html:

    <section class="cont-content work" id="work">
        <h1>work</h1>
        <article class="view">
            <img src="images/g.jpg" alt="">
                <div class="mask">
                    <h2>Title</h2>
                        <p>subtitle</p>
                    <a href="#" class="info">Read More</a>
                </div>
        </article>

        <article class="view">
            <img src="images/m.jpg" alt="">
                <div class="mask">
                    <h2>title</h2>
                        <p>subtitle</p>
                    <a href="#" class="info">Read More</a>
                </div>
        </article>

        <article class="view">
            <img src="images/p.jpg" alt="">
                <div class="mask">
                    <h2>title</h2>
                        <p>subtitle</p>
                    <a href="#" class="info">Read More</a>
                </div>
        </article>          
    </section>

Thanks!

markens
  • 113
  • 6

4 Answers4

0

Yes

   #work article:first-of-type .mask 

is what you are looking for then

Four_lo
  • 1,150
  • 10
  • 28
0

CSS3 :nth-of-type() Selector

.view:nth-child(2) .mask {
  background: lightblue;
}
<section class="cont-content work" id="work">
  <h1>work</h1>

  <article class="view">
    <img src="images/g.jpg" alt="">
    <div class="mask">
      <h2>Title</h2>

      <p>subtitle</p> <a href="#" class="info">Read More</a>

    </div>
  </article>
  <article class="view">
    <img src="images/m.jpg" alt="">
    <div class="mask">
      <h2>title</h2>

      <p>subtitle</p> <a href="#" class="info">Read More</a>

    </div>
  </article>
  <article class="view">
    <img src="images/p.jpg" alt="">
    <div class="mask">
      <h2>title</h2>

      <p>subtitle</p> <a href="#" class="info">Read More</a>

    </div>
  </article>
</section>
vanburen
  • 21,502
  • 7
  • 28
  • 41
0

Use nth-child()

.view:nth-child(2) .mask {
 font-family: Arial;
}

http://codepen.io/anon/pen/RPvgjP

Paul Redmond
  • 3,276
  • 4
  • 32
  • 52
0

Given the structure you have I would select the first article inside the specific section (which has an ID) and go from there:

#work article:first-of-type .mask {
    /* your styles here */
 }

Oh, by the way, first-child / first-of-type etc. are pseudo-classes not pseudo-elements.

Paulie_D
  • 107,962
  • 13
  • 142
  • 161