2
In this example below there is an element .title. And in it I’m putting one first-child with margin-top:20px;.
When compiling and saving is not working. Do not apply the top margin on the first element of this type.
LESS
What happens ?
.linha-infantil{
background-color: #44A5D7;
border-radius: 10px;
padding: 10px;
box-sizing: border-box;
.faixa-amarela{
line-height: 40px;
color: #000;
width: 100%;
background-color: #FFF;
text-align: center;
border-radius: 10px;
font-size: 20px;
}
.title{
font-size: 46px;
color: #FFF;
text-align: center;
font-family: "Candara";
&:first-child{
margin-top: 20px;
}
}
.owl-carousel{
.item{
padding: 30px;
}
}
}
HTML
<div class="linha-infantil">
<div class="faixa-amarela">
Linha Infantil
</div>
<div class="title">DIA</div>
<div class="owl-carousel">
<div class="item">{{ HTML::image('img/marcas/') }} </div>
<div class="item">{{ HTML::image('img/marcas/') }} </div>
<div class="item">{{ HTML::image('img/marcas/') }}</div>
<div class="item">{{ HTML::image('img/marcas/') }} </div>
</div>
<div class="title">EQUATE</div>
<div class="owl-carousel">
<div class="item">{{ HTML::image('img/marcas/') }} </div>
<div class="item">{{ HTML::image('img/marcas/') }} </div>
</div>
</div>
I don’t understand. I’m making a
&:first-childin the specific element.titleand not in the parent element.linha-infantil. I’ve used this onefirst-of-type. Unsuccessful too. I’m using Codekit. This program already compiles code that works for all browsers.> 5%, last 5 versions, ie >= 5.5, ff >= 2, Chrome >= 4, Safari >= 3.1, Opera >= 9.5,ios >= 3.2, android >= 2.1– Diego Souza
I was talking nonsense to
:first-of-type: the definition of "first" is specific to tags, it seems. Having said that, I made a Jsfiddle illustrative::first-childis a property that applies to son, and not to the father, in spite of whom is the first child depend, obviously, on the father.– user25930
So in Jsfiddle I put one
<p>Teste</p>above the firstspanof the firstdiv. And did not heed thebackgroundin the firstspan. Only on the seconddiv, in the firstspanwho accepted. And you specified for thespanin CSS. So the same thing is happening to me. I’m going to have to create a separate class, like,.marginTopand set in the first elementdiv.title. But I really wanted to use the pseudo-element.– Diego Souza
:first-childworks that way; it is intentional that it stops receiving the background. I think you are suffering because the structure of your document is not compatible with the semantics of your document. Why do you want to use the pseudo-element? Because the HTML I put in the answer is no better from your point of view?– user25930
1 - Why do I want to use the pseudo-element ? - I am using LESS. 2 - Why is the HTML you put in the answer not better from my point of view ? - Exactly. And it didn’t work and the structure of my HTML is exactly as it has to be. It can’t be like your Jsfiddle. But thank you.
– Diego Souza