简体   繁体   中英

Will CSS attribute selector work to style this element?

I have the following 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.

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.

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;

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

Use two classes for ex:- 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 .

Hope that helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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