css - 如何使用 before 选择器 css 添加 li

标签 css sass

我正在尝试在列表中的 li 之前添加一个 li:

ul.ssmenu:first-child::before{
    li{
        position: relative;
        height: 10px;
    }
}

这似乎不是正确的解决方案。

最佳答案

你不能只使用 CSS 添加这样的元素,::before 是一个元素,一个伪元素,你可以这样做......,如果你需要更多li,你需要使用脚本

ul li,
ul::before,
ul::after {
  position: relative;
  height: 20px;
}
ul::before {
  content: 'This li were added with CSS pseudo ::before';
  display: list-item;
}
ul::after {
  content: 'This li were added with CSS pseudo ::after';
  display: list-item;
}
<ul>
  <li>This "li" exist in markup</li>
</ul>

关于css - 如何使用 before 选择器 css 添加 li,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42198651/

相关文章:

css - SASS 响应式网格混合

css - 无法获取 css 表格数据以卡住第一列

css - 为什么格式在 font-face 中使用 'format(' extension_here 声明两次')'

javascript - 页面的 CSS 输入动画

html - 为什么我在这个网站上的移动菜单在浏览器上有效,但在实际移动设备上却无效?

css - 在使用 SASS 的现有元素中找不到 config.rb

html - 快速编辑我的网站的简单方法

javascript - 我应该如何在 IE 6 中通过背景重复使用透明 png?

css - 在不更改 jekyll 代码块样式的情况下显示行号

node.js - 使用grunt-sass编译node-sass,报错 "Fatal error: The "original"argument must be of type function."