在没有添加任何类(或触摸HTML)的情况下,如果该div中有第二个元素,有没有办法将div中的第一个元素作为目标?以下是我的HTML:
<div class="grid">
<div class="content">I WANT TO APPLY CSS TO THIS</div>
<div class="content">But only if there is 2nd .content element in the same parent element</div>
</div>
<div class="grid">
<div class="content">Don't apply here</div>
</div>
<div class="grid">
<div class="content">Don't apply here</div>
</div>
<div class="grid">
<div class="content">I WANT TO APPLY CSS TO THIS</div>
<div class="content">But only if there is 2nd .content element in the same parent element</div>
</div>
Run Code Online (Sandbox Code Playgroud)
为了获得更好的图片,可以使用一些上下文...我想把.content它放在中心,如果它是内部唯一的.content .grid.但如果有两个.contentdiv,那么我希望它们彼此相邻.
注意:
我已经知道我可以瞄准第二个.content了
.grid .content:nth-child(2) { ... …Run Code Online (Sandbox Code Playgroud) 我想要一个非常简单的汉堡菜单。我使用 jQuery 在单击汉堡包时将其切换为打开和关闭。但我希望用户在单击 div 或菜单之外的任何位置时能够关闭它。
jsfiddle是我写出来的。别介意造型。
我想用类似的东西
$(window).on('click', function(){
$('.responsive-menu').removeClass('expand');
})
Run Code Online (Sandbox Code Playgroud)
但添加后,我什至无法打开菜单。请帮忙。谢谢你!