<...">

Apply CSS for the first div label

I would like to apply specific css to a specific label in my html this is my 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 a lot of pseudo classes, but I did not find any solution, any idea please?

+4
source share
5 answers

try using this shortcut inside div in registration

#registration > div > label{
   //your css
}

Demo

+9
source

Just give it a class. Classes can be repeated in HTML, for example:

<label class="class1">Localisation</label>

and in your css,

.class1{
  //styling
}
+3
source

CSS3

#registration div label:first-child {
    // specific styles for just the first label item
}

#registration div label:nth-first-of-type{
// specific styles for just the first label item
}

jQuery Way

<script>
$( "#registration div label:first" ).css( "font-style", "italic" );
</script>
+3

, , div.

div > label:first-child {}

, . , div, . .

0

#registration > div > label:first-of-type {}

?

0

All Articles