Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

<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 ?

like image 510
hamza437 Avatar asked Dec 26 '13 10:12

hamza437


People also ask

How do I select the first label in CSS?

You can't use className in inline html. Use class instead. Also make sure the class is the same as the one you are using in the css. :first-child selects the first child of label.

How do I label a div in CSS?

<input type="search"> <input type="tel"> <input type="text">

How do you target the first element in CSS?

The :first-child selector allows you to target the first element immediately inside another element. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.

How do I select the first sibling in CSS?

It is possible to target first sibling with CSS, with some limitations. This works, but requires that you can explicitly set the styles on the siblings to override the setting for first child. But if your html is dynamic and sometimes you'll only have a single li. heading, it'll be hidden.


1 Answers

try this way where you can style all your label inside the div contained into registration

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

DEMO

like image 99
Alessandro Minoccheri Avatar answered Nov 03 '22 00:11

Alessandro Minoccheri