-2

Anyone know how to select first div of mutliple div with same class name

<div class="abc"><a><img src=""></a></div>
<div class="abc"><a><img src=""></a></div>

how can i select first img in css?

hkguile
  • 4,235
  • 17
  • 68
  • 139

2 Answers2

0

You can use first-child pseudo class

.abc:nth-of-type(1)
{
  height:100px;
  width:100px;
  background:red
  }
<div class="abc"><a><img src=""></a></div>
<div class="abc"><a><img src=""></a></div>
Sankar
  • 6,908
  • 2
  • 30
  • 53
0
div:nth-of-type(1)  {
   color: white;[enter link description here][1]
 }

demo

Richa
  • 4,240
  • 5
  • 33
  • 50
  • Although this code may help to solve the problem, it doesn't explain _why_ and/or _how_ it answers the question. Providing this additional context would significantly improve its long-term educational value. Please [edit] your answer to add explanation, including what limitations and assumptions apply. – Toby Speight Aug 22 '16 at 14:12
  • if i use abc:nth-of-type (1), it is not work – hkguile Aug 23 '16 at 02:48