1

I want to give border to the first div with the class block in the code below:

<div class="col-md-4 news">
            <h3>News Feed</h3>
            <div class="block">
              <p class="date"><span>15</span>march</p>
              <p><a href="#">serving people from 23 branches all over the nepal</a></p>
              <div class="clearfix"></div>
            </div>
            <div class="block">
              <p class="date"><span>17</span>march</p>
              <p><a href="#">serving people from 23 branches all over the nepal</a></p>
              <div class="clearfix"></div>
            </div>
          </div>
Sushil Thapa
  • 564
  • 7
  • 17
  • 4
    possible duplicate of [CSS selector for first element with class](http://stackoverflow.com/questions/2717480/css-selector-for-first-element-with-class) – Peter Jun 19 '15 at 07:15

7 Answers7

4

I would suggest

.block:first-of-type {
 border: yourborder;
}
2
  .col-md-4 .block:first-of-type{
      border:1px solid RED;
   }
Keith A
  • 771
  • 6
  • 12
2

You can use the first-of-type pseudo selector for this:

.news .block:first-of-type {border:1px solid #000;}

Fiddle Here

rch
  • 91
  • 2
  • 7
2

This will work

.block:first-of-type {
    border:solid 1px #ccc;    
}
1

Use first-of-type selector. Source here

.block:first-of-type {
    border:2px solid red;
}

JSFiddle

freewheeler
  • 1,306
  • 2
  • 12
  • 24
1

with following code:

.news > div:first-child
ahmad valipour
  • 293
  • 2
  • 11
0

Try:

.col-md-4.news h3 + .block{ border:solid 1px #000; }
Rajiv007
  • 1,126
  • 7
  • 13