当另一个特定的 NESTED 元素在前面时,如何不选择一个元素?

问题描述

我正在尝试选择所有 <ul> 元素,这些元素Not 之前是一个 <mark> 元素直接嵌套在一个 <p>元素。

换句话说

我只想选择不跟随带有 <ul> 元素的段落 <p> 元素作为其最后一个子元素的 <mark> 元素。


我尝试了多种方法,例如 p:not(p > mark) + ul{}p:not(p) > mark + ul{}
但是 CSS 规则选择太多(所有 ul 元素)或太少(根本没有 ul 元素)。

我忽略了什么?谢谢! js fiddle demo

/* CSS */
/* Select ul elements that are not preceeded by a nested <mark> element as last child of the preceding paragraph p element */

p:not(p > mark) + ul{
  margin-top: 2em;
  }
<p>
  Text Text Text
</p>

<ul>
  <!-- This ul element should BE selected -->
  <!-- There should be a margin above this list -->
  <li>List item</li>
  <li>List item</li>
  <li>List item</li>
</ul>


<hr>


<p>
  Text Text Text<br>
  <mark>Marker</mark><!-- Look out for this element inside preceding paragraph -->
</p>

<ul>
  <!-- This ul element should NOT be selected -->
  <!-- There should be NO margins above this list -->
  <li>List item</li>
  <li>List item</li>
  <li>List item</li>
</ul>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...