简体   繁体   English

以某个嵌套类定位div

[英]Target a div with a certain nested class

I've got the following code several times on a page: 我在页面上多次获得以下代码:

<div>
    <input class="entry">
</div>

I want to target the div tag through css without creating a class or id. 我想通过css定位div标签而不创建类或id。 Is this possible? 这可能吗?

I tried div.entry { foo } and .entry div {foo} neither seemed to work. 我尝试了div.entry { foo }.entry div {foo}似乎都不起作用。

You're not targeting the div with that CSS, you'll need to select the parent of the input that has the entry class. 您没有使用该CSS定位div,而是需要选择具有条目类的输入的父级。 However, there's no way of doing this in current CSS but with selector specs of CSS4, which could be done as follows: 但是,当前的CSS无法做到这一点,而只能使用CSS4的选择器规范,具体操作如下:

div! > input.entry { foo }

AFAIK, there's no browsers supporting this yet, so you'll have to use JavaScript. AFAIK,尚无浏览器支持此功能,因此您必须使用JavaScript。

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

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