Reputation: 502
I want to apply margin top:15px to only 1st element of this div
I am pulling ckeditor data from database that is why 1st element is unpredictable
This is my div structure ,
<div class="ckeditordata">
//1st element is unknown
//can be <p>, <ul>, <ol>
</div>
Upvotes: 3
Views: 2042
Reputation: 35
.selector> *:nth-child(1) {
color: green;
margin-top: 20px;
font-weight: 600;
}
<div class="selector">
<p>TEXT</p>
<p>TEXT</p>
<p>TEXT</p>
</div>
Upvotes: 1
Reputation: 10216
You can use css >
child selector with :nth-child(1)
to apply css only for 1st child like this:
.ckeditordata > *:nth-child(1) {
color: red;
margin-top: 15px;
}
<div class="ckeditordata">
<p>TEXT</p>
<p>TEXT</p>
<p>TEXT</p>
</div>
Upvotes: 2
Reputation: 32921
You can use :first-child
.
.ckeditordata > :first-child {
margin-top: 15px;
}
Quick demo: https://jsfiddle.net/crswll/1re2p8sp/2/
Upvotes: 9
Reputation: 162
You can use through jQuery also. Check this code, if it works:
$('.ckeditordata').children(':nth-child(1)').css('margin-top','15px');
Upvotes: 0