[英]apply CSS for the first label of div
i would like to apply a specific css to a specific label in my html this is my HTML 我想将特定的CSS应用于我的HTML中的特定标签,这是我的HTML
<div id="registration">
<div>
<label>Localisation</label>**//this is the target label to apply css**
<div id="registration_localisation">
<div>
<label>Gouvernorat</label>
<select id="registration_localisation_gouvernorat">
<option value="1">Ariana</option>
<option value="2">Ben Arous</option>
<option value="3">Bizerte</option>
</select>
</div>
<div>
<label for="registration_localisation_ville">Ville</label>
<input type="text" id="registration_localisation_ville">
</div>
</div>
</div>
<div>
<label>Annonceur</label>**//this is the target label to apply the css**
<div id="registration_annonceur">
<div>
<label for="registration_annonceur_Nom">Nom</label>
<input type="text" id="registration_annonceur_Nom">
</div>
<div>
<label for="registration_annonceur_Email">Email</label>
<input type="text" id="registration_annonceur_Email">
</div>
<div>
<label for="registration_Telephone" >Telephone</label>
<input type="text" id="registration_annonceur_Telephone">
</div>
</div>
</div>
</div>
i used many pseudo classes but i didn't find any solution any idea please ? 我使用了很多伪类,但我没有找到任何解决方案吗?
Just give it a class. 给它上课吧。 Classes may be repeated in HTML, like;
类可以用HTML重复,比如;
<label class="class1">Localisation</label>
and in your css, 在你的CSS中,
.class1{
//styling
}
CSS3 way CSS3方式
#registration div label:first-child {
// specific styles for just the first label item
}
Or 要么
#registration div label:nth-first-of-type{
// specific styles for just the first label item
}
jQuery Way jQuery方式
<script>
$( "#registration div label:first" ).css( "font-style", "italic" );
</script>
How about 怎么样
#registration > div > label:first-of-type {}
? ?
Match labels who are the first, direct child of a div. 匹配作为div的第一个直接子项的标签。
div > label:first-child {}
Actually it would be much better if you could add some classes to your elements. 实际上,如果你可以为你的元素添加一些类会好得多。 Matching wide selector such as
div
is a bad idea for future maintainability. 匹配宽选择器(如
div
)对于将来的可维护性来说是一个坏主意。 Changing your markup will break your style. 改变你的标记会破坏你的风格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.