开发者

Could it be possible to make css selector affect other elements in the page without javascript? [duplicate]

This question already has answers here: How to affect other elements when one element is hovered (8 answers) 开发者_StackOverflow中文版 Closed 8 years ago.

For example, I want to make two textboxes have the same style when either is focused:

<div class="divTxt">
    <input type="text" id="a" class="a" />
    <input type="text" id="b" class="b" />
</div>

and the css would be:

.a:focus 
{
    background-color:Blue;
}
.b:focus 
{
    background-color:Yellow;
}

What I need is make a's background-color:Yellow when b is focused and vice versa. any possibilities? Thanks a lot.


You could try the General Sibling Selector(~) if the input boxes are next to each other.

Something like:

.a:focus {    background-color:Blue;}
.a:focus~.b {    background-color:Blue;}
.b:focus {    background-color:Yellow;}
.b:focus~.a {    background-color:Yellow;}

Note: Completely untested and a stab in the dark at best!


If they've got javascript disabled, they probably won't notice text box styles.


.chk1:focus{
   background-color:Blue;
}
.chk2:focus{
   background-color:Yellow;
}

text feilds

<input class=chk1 type=text id="a">
<input class=chk2 type=text id="b">

This one will work fine with FireFox but might have issues with IE6 See CSS Issue Focus For IE6

If you want this to work with IE, you might want to use javascript!!

Hope this helps

RDJ

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜