简体   繁体   English

CSS属性选择器是否可以设置此元素的样式?

[英]Will CSS attribute selector work to style this element?

I have the following html: 我有以下html:

<div class="bf_form_row">
    <label for="findout">Text goes here</label>
<textarea class="findOut" cols="40" id="findout" name="findout" rows="10"></textarea>
</div>

I trying to work out how to style the 'label' element without being able to change the html. 我试图找出如何设置'label'元素的样式,而无法更改html。

Ideally I'd like to style all 'label' elements that come before 'textarea' elements but I don't think it is possible using just CSS. 理想情况下,我想设置'textarea'元素之前的所有'label'元素,但我不认为只使用CSS。

I thought this attribute selector would work: 我认为这个属性选择器可以工作:

label[for="findout"] {
    width: 100%;
}

but no, any ideas? 但不,有什么想法吗?

It works. 有用。 To see it in action, try changing the color. 要查看它的实际效果,请尝试更改颜色。 Anyway, if you want the width to be 100%, I would suggest adding display: block; 无论如何,如果你想宽度为100%,我建议添加display:block;

label[for="findout"] {
    display: block;
    width: 100%;
}

Use two classes for ex:- 1] before_textarea 2] after_textarea 使用两个类,例如: - 1] before_textarea 2] after_textarea

.before_textarea {
    width: 100%;
   // style to label which comes before teaxtarea
}

.after_textarea {
    width: 100%;
   // style to label which comes after teaxtarea
}

Use the selector: 使用选择器:

.bf_form_row label
{
styles
}

This will select all label elements inside the parent with class of bf_form_row . 这将选择父类中的所有标签元素,类为bf_form_row

Hope that helps :) 希望有帮助:)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM