html - 使用伪元素作为有序列表的样式,同时保留缩进

标签 html css

我遇到 CMS 正在生成表单列表的情况

<ul>
    <li>
        <a>Here's list item 1, which will wrap onto the next next due to the size of the ul element containing it</a>  
    </li>
    <li>
        <a>Here's list item 2, which will wrap onto the next next due to the size of the ul element containing it</a>          
    </li>
    <li>
        <a>Here's list item 3, which will wrap onto the next next due to the size of the ul element containing it</a>          
    </li>
</ul>

我需要客户希望列表样式为 '>' 字符并且颜色与文本不同。所以我决定使用经典的伪元素 hack,但现在的问题是我希望文本在换行到下一行时对齐,就像在普通列表中一样。我已经在 lili:before 元素上尝试了 padding/text-indent/margin 的所有组合,但无法正确处理。

这是场景的 fiddle :

http://jsfiddle.net/t0wxsf0j/

最佳答案

你能给你的伪元素一个负边距吗:

ul > li:before {content: ">";margin-left:-.8em;}

http://jsfiddle.net/t0wxsf0j/1/

关于html - 使用伪元素作为有序列表的样式,同时保留缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27006420/

相关文章:

html - 悬停时更改背景颜色

带有背景图片的 CSS 假 HR

jquery - 如何使用CSS3、jQuery、HTML制作图片队列效果?

css - "--"是有效的 CSS3 标识符吗?

html - 如何将这些 html 元素对齐成一行?

asp.net - 外部 css 中的哪些选择器名称?

javascript - 如何为响应式导航栏添加折叠时的平滑过渡?

html - 将边框半径应用于表格的最后一行(使用 ng-repeat)

javascript - Z-index 'breaks' 幻灯片点击按钮

html - Blogger 中的导航栏