简体   繁体   English

奇怪的CSS显示问题

[英]Strange CSS displaying issue

I'm managing a <a> 's element display with jquery. 我用jquery管理<a>的元素显示。 Based on some keypress events, it appends or removes an <input> 's class (responsible with display management) that has a sibling relationship with the mentioned <a> . 基于一些按键事件,它会附加或删除与所提及的<a>具有兄弟关系的<input>类(负责display管理)。

The problem is that, i have a selector that uses CSS + . 问题是,我有一个使用CSS +的选择器。 And for some reason, in Chrome (im not sure about other browsers since i have not tested), it won't display:block the <a> element when the sibling <a> has the class. 由于某种原因,在Chrome中(我不确定其他浏览器,因为我没有测试),它不会display:block当兄弟<a>有类时display:block <a>元素。

HTML HTML

<div class="cont">
    <input class="myInput"/>
    <label>S</label>
    <a>X</a>
</div>

CSS CSS

.cont {
    position: relative;
}
a {
    position: absolute;    
    left: 117px;
    top: 3px;
    display: none;
}
label {
    position: absolute;
    left: 140px;
    top: 3px;
}
.has_typed + label + a {
    display: block;
}

Script 脚本

$("input").on('keyup', function(){
    var thiss = $(this);
    if (thiss.val() != 0 && !(thiss.hasClass('has_typed'))) {
        thiss.addClass('has_typed');
    }
    else if (thiss.val() == 0) {
        thiss.removeClass('has_typed');
    }
});

Fiddle here: http://jsfiddle.net/aF4qt/1/ 这里小提琴: http //jsfiddle.net/aF4qt/1/

Change: 更改:

.has_typed + label + a { ... }

To: 至:

.has_typed ~ label + a { ... }

http://jsfiddle.net/JamesD/aF4qt/7/ http://jsfiddle.net/JamesD/aF4qt/7/

If you are doing every thing in jQuery then why not do the rest using jQuery itself. 如果你在jQuery中做所有的事情,那么为什么不使用jQuery本身做其余的事情。

Try this: 试试这个:

$('.has_typed + label + a').show();

Not sure though why the same was not working in css 不确定为什么同样不能在CSS中工作

Working Fiddle 工作小提琴

This will also work if you have multiple groups. 如果您有多个组,这也可以使用。

Check this fiddle 检查这个小提琴

Check this link for more info. 请查看此链接以获取更多信息。

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

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