简体   繁体   English

将CSS应用于div的第一个标签

[英]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 ? 我使用了很多伪类,但我没有找到任何解决方案吗?

try this way where you can style all your label inside the div contained into registration 尝试这种方式,您可以在registration包含的div内设置所有标签的样式

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

DEMO DEMO

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. 改变你的标记会破坏你的风格。

将 CSS 样式应用于<div></div><div id="text_translate"><p>我的问题是下面的 html</p><pre> &lt;div class="editor-container"&gt; &lt;div class="editor-row curFocus"&gt; &lt;div class="editor-label"&gt; &lt;label for="FirstName"&gt;First Name&lt;/label&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;input class="text-box single-line valid" id="FirstName" name="FirstName" type="text" value="Nancy" maxlength="20"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> 当用户选择输入字段时,我通过一些 javascript 将 class "curFocus" 添加到外部 div 以突出显示 label 和输入字段。</p><p> 我的 css 是 -</p><pre> .editor-container { border: thin solid #444444; display: table; width: 100%; }.editor-row { width: 100%; display: table-row; }.editor-label { padding-left: .4em; width: 40%; }.editor-label, .editor-field { padding-right: .4em; padding-bottom: .2em; padding-top: .2em; display: table-cell; }.curFocus { border: 2px solid #05365b; background-color: #d3e5f2; margin: 3px; padding: 3px; }</pre><p> 我的问题是,在 Chrome 12 和 IE9 中使用调试器时,它们都显示了应用于外部 div 的边框设置。 但是,在查看表单时,浏览器都不会显示指定的边框。 所有其他 css 设置工作正常。 我还尝试将“.curFocus”的定义更改为“.curFocus div”。 但这也将样式应用于每个嵌套的 div,但确实在所有 div 上显示了边框。</p><p> 虽然我不是 CSS 专家,但不清楚为什么这不起作用。</p><hr><p> 编辑这里是 jsfiddle 链接 - <a href="http://jsfiddle.net/photo_tom/KmsF5/1/" rel="nofollow">http://jsfiddle.net/photo_tom/KmsF5/1/</a> 。 在进行测试时,如果在 IE7 兼容模式下,它确实可以在 IE9 中正常工作。 否则,它不能正确显示。 很抱歉不包括链接,仍然习惯了 jsfiddle 甚至存在的事实。</p></div> - Apply CSS style to <div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 CSS 样式应用于 Div 的兄弟标签字段? - How to apply CSS style to a Sibling Label field of a Div? 在 CSS 中,'div:first-of-type[label="hello"]' 与 'div[label="hello"]:first-of-type' 不同吗? - In CSS, is 'div:first-of-type[label=“hello”]' different from 'div[label=“hello”]:first-of-type'? 如何使用CSS在div中选择第一个标签? - How to select first label within div using css? GWT-第一步-Div + label + css样式 - GWT - First Steps - Div+label+css style 如何将css属性应用于我的第一个div类 - how to apply css property to my first div class only 将CSS效果仅应用于<a>div</a>的前10个<a>标记</a> - Apply a CSS effect to only the first 10 <a> tags of a div CSS适用于所有内部div但跳过第一个孩子 - CSS apply to all inside div but skip first child 如何在CSS中的h2之后将样式应用于第一个div? - How to apply style to first div after h2 in css? <a>在div中</a>特别应用CSS - Apply CSS on particular <a> in a div 将 CSS 样式应用于<div></div><div id="text_translate"><p>我的问题是下面的 html</p><pre> &lt;div class="editor-container"&gt; &lt;div class="editor-row curFocus"&gt; &lt;div class="editor-label"&gt; &lt;label for="FirstName"&gt;First Name&lt;/label&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;input class="text-box single-line valid" id="FirstName" name="FirstName" type="text" value="Nancy" maxlength="20"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> 当用户选择输入字段时,我通过一些 javascript 将 class "curFocus" 添加到外部 div 以突出显示 label 和输入字段。</p><p> 我的 css 是 -</p><pre> .editor-container { border: thin solid #444444; display: table; width: 100%; }.editor-row { width: 100%; display: table-row; }.editor-label { padding-left: .4em; width: 40%; }.editor-label, .editor-field { padding-right: .4em; padding-bottom: .2em; padding-top: .2em; display: table-cell; }.curFocus { border: 2px solid #05365b; background-color: #d3e5f2; margin: 3px; padding: 3px; }</pre><p> 我的问题是,在 Chrome 12 和 IE9 中使用调试器时,它们都显示了应用于外部 div 的边框设置。 但是,在查看表单时,浏览器都不会显示指定的边框。 所有其他 css 设置工作正常。 我还尝试将“.curFocus”的定义更改为“.curFocus div”。 但这也将样式应用于每个嵌套的 div,但确实在所有 div 上显示了边框。</p><p> 虽然我不是 CSS 专家,但不清楚为什么这不起作用。</p><hr><p> 编辑这里是 jsfiddle 链接 - <a href="http://jsfiddle.net/photo_tom/KmsF5/1/" rel="nofollow">http://jsfiddle.net/photo_tom/KmsF5/1/</a> 。 在进行测试时,如果在 IE7 兼容模式下,它确实可以在 IE9 中正常工作。 否则,它不能正确显示。 很抱歉不包括链接,仍然习惯了 jsfiddle 甚至存在的事实。</p></div> - Apply CSS style to <div>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM