html - 如何缩进自定义无序列表中的文本

标签 html css html-lists

fiddle :http://jsfiddle.net/pgf0ckfj/1/

CSS:

ul {
    list-style: none;
    padding: 0 0 0 45px;
}
ul li:before {
    content: "♦ ";
    color: #E55302;
}

如您所见,文本没有像普通 UL 那样缩进。

如何修改 CSS 以确保文本缩进以防止溢出到下一行的任何内容。

最佳答案

li 设置为 position: relative; 然后将你的伪元素设置为 position: absolute; 以及一个负数 left 值。添加相对定位将确保您的绝对定位伪元素将根据 li 的位置和大小自行定位。

ul {
    list-style: none;
    padding: 0 0 0 45px;
}
ul li:before {
    content: "♦";
    color: #E55302;
    position: absolute;
    left: -15px;
}
li {
  position: relative;
  }
<ul>
	<li>This is the first entry but only goes one line</li>
	<li>This is the second entry but only goes one line</li>
	<li>This is the third entry but it can go many many many lines and sometimes even a whole paragraph and I would like the text to be indented from the bullet.</li>
	<li>This is the fourth entry but only goes one line</li>
	<li>This is the third entry but it can go many many many lines and sometimes even a whole paragraph and I would like the text to be indented from the bullet.</li>
</ul>

关于html - 如何缩进自定义无序列表中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31677241/

相关文章:

html - 使用 CSS 突出显示当前页面的代码不适用于 IE

html - 使html的一部分可滚动

css - HTML 显示原始文本

html - 使用菜单脚本时,它只 float 在左侧。我怎样才能把DIV的中心

javascript - 如何创建反向无序列表?

html - HTML/CSS 中 LI 工具栏中的自定义图像

html - Angular1 : TypeError: promise. catch 不是函数

html - 使列的宽度固定并将单词换行到下一行

javascript - TinyMCE 和 HTML

html - 同位素图像从元素的中心开始