html - 基于样式的 CSS 选择器

标签 html css

是否可以根据元素的样式声明 css 路径? 例如,我的页面上有两个 ul 元素。其中之一具有样式 list-style-type: lower-alpha; :

<ul start="1" style="list-style-type: lower-alpha;">

第二个 ul 没有 list-style-type 样式:

<ul start="1">

我需要将 css 应用到具有 list-style-type 的 ul 元素。这样的css选择器路径怎么写?

主要问题是我在同一页面上有数字 ul 和小写字母 ul 元素,并且我想在字母和数字 ul 中制作粗体数字。即,现在我使用

.ts4page  ul,ol li:before {
    content: counter(item, lower-alpha) ". ";
    counter-increment: item;
    font-weight: bold;
    margin-bottom: 3px;
}

但它使页面上的所有 ul 都变成 lower-alpha,但不仅仅是 ul,具有 style="list-style-type: lower-alpha;" 样式。

谢谢!

最佳答案

您可以使用属性选择器[style="list-style-type: lower-alpha;"]

ul[style="list-style-type: lower-alpha;"] {
  color: green;
}
<ul start="1" style="list-style-type: lower-alpha;">
  <li>Li</li>
  <li>Li</li>
</ul>
<ul start="1">
  <li>Li</li>
  <li>Li</li>
</ul>

如果您有更多内联样式,可以使用[attr*=value]来查找list-style-type: lower-alpha;作为子字符串

ul[style*="list-style-type: lower-alpha;"] {
  color: green;
}
<ul start="1" style="opacity: .7; list-style-type: lower-alpha; font-size: 12px;">
  <li>Li</li>
  <li>Li</li>
</ul>
<ul start="1">
  <li>Li</li>
  <li>Li</li>
</ul>

关于html - 基于样式的 CSS 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41998961/

相关文章:

html - 当超过div的宽度时如何截断文本

css - 所有主要浏览器上带有 css 的不可见(透明)字体颜色

html - 我的页脚不会粘在底部

javascript - 如何将列表作为参数传递给对话框?

Javascript - 在两个图像之间切换

html - 导入网页通用结构

javascript - 在移动菜单中创建智能下拉级别

c++ - 通过网页和Widgets设置CSS样式

html - CSS 形状 - 三 Angular 形设计

javascript - Ajax 调用后 JS 库不工作