English 中文(简体)
• 如何利用CSS邻近的选定儿童课程?
原标题:How to use the CSS adjacent selector based on nested child classes?

I can use the adjacent selector like this:

/* When c and c are adjacent, color the second c red */

.c + .c {
  background-color: red;
}

但是,当“.c”被nes时,如何做同样的事情?

<div class="a">
  <div class="b">
    <div class="c"></div>
  </div>
</div>
<div class="a">
  <div class="b">
    <div class="c"></div>
  </div>
</div>

/* Does not work */
.a .b .c + .a .b .c {
  background-color: red;
}
最佳回答

对于相邻的选任人<代码>+,两个选任人必须持平。

因此,它必须成为<条码>a + .a,因为它们是你在座标中唯一毗邻的要素。 然后,可选择第二个<代码>.as child content:.a + .a.b.c。 之后,您可限制第1条<代码>.a,以确保其也有儿童要素.b.c,使用:has(<>>>> p:

.a:has(.b .c) + .a .b .c

.a:has(.b .c) + .a .b .c {
  background-color: red;
}
<div class="a">
  <div class="b">
    <div class="c">1</div>
  </div>
</div>
<div class="a">
  <div class="b">
    <div class="c">2</div>
  </div>
</div>
问题回答

在这种情况下,你可以直接由相邻的挑选人进入。

由于相邻的兄弟姐妹选择人用来选择一个与另一个具体要素直接相关的要素。 Si子必须具有相同的母子成分,“邻里”是指“立即跟踪”。

因此,在这种情况下,你可以使用+作为目标。

.a + .a .b .c{
    background-color: red;
}
<div class="a">
    <div class="b">
        <div class="c">First C</div>
    </div>
</div>
<div class="a">
    <div class="b">
        <div class="c">Second C</div>
    </div>
</div>

社会保障局没有按照你的要求提供选择要素的途径。 但是,如果可能的话,应修改超文本结构,以适应(例如,在<代码>的集装箱内添加一个类别或属性。 如果无法改变超文本结构,你就可以利用 Java或 j子来做到这一点。

如果没有修改超文本结构或使用Java或jQuery的能力,我恐怕完全没有办法只与安保部实现这一点。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签