开发者

Is it possible to select an an element that immediately precedes another element using the adjacent selector

I would like to select <label> elements that immediately precede <input type="checkbox">

from the CSS guide

Adjacent sibling selectors have the following syntax: E1 + E2, where E2 is the subject of the selector.

But, unless I'm m开发者_Python百科isunderstanding the spec I need a select where E1 is the subject not E2. I'm sure this must be available, what am I missing?


Actually no, youre not missing anything (unless i have been for quite some time now as well) - you cant select a previous sibling with css2 selectors.


I've never used it, but I understand from the link that you've provided that it should be done exactly like follows:

input[type='checkbox'] + label { color: Red }

This should work for the next HTML:

<input type='checkbox' id='chckTest' /><label>Test checkbox</label>

I don't have the possibility to check it now but I believe that the "Test checkbox" text will be red...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜