在这里拉小提琴:
https://jsfiddle.net/sgbotsford/d52zyp0t/72/
额外的第一行缩进是从哪里来的
<li>
使用=>:在满足之前?
问题是。我无法控制的情况将段落标记放在列表元素中。当我使用a:before时,它是一个负数左边,它在页边空白处,就像我想要的那样。但是文本缩进在我之前使用的地方增加了:before。这个额外的缩进是从哪里来的?
期望的行为是段落和列表项的样式相同,除了=>在左边空白处浮动。
我相信我最终可以做足够多的实验来破解一个解决方案,但现在我正试图从盒子模型的角度来理解这种行为。
一个答案建议从中删除文本缩进标记
<p>
这会导致一次冲水
<
还有一个较小的缩进
<李>
HTML
<html>
<head>
</head>
<body>
<div class=content>
<p>This is a paragraph. It has several sentences. It goes on and on and on and on. It has several sentences. It goes on and on and on and on. </p>
<ul class="c">
<li><p>This is a list element that is long enough to wrap, I think. But it needs to be longer to check justification. It looks a lot like a paragraph.</p></li>
<li><p>This is a list element that is long enough to wrap, I think. But it needs to be longer to check justification.</p></li>
</ul>
<ul class="b">
<li><p>This is a list element that is styled using ::before and outdenting the content. Where does the extra space come from? </p></li>
<li><p>This is a list element that is long enough to wrap, I think.</p></li>
</ul>
</div>
</body>
</html>
CSS
body {
text-align: justify;
hyphens: auto;
margin-left: 3rem;
}
.content {
width: 40rem;
background-color: yellow;
}
p {
width: 15rem;
margin: auto;
margin-top: 0.6rem;
background-color: lightgreen;
padding: 0;
font-style: normal;
font-size: 1.25rem;
line-height: 1.4rem;
text-indent: 1rem;
text-align: justify;
hyphens: auto;
word-break: break-word;
}
ul {
list-style-type: none;
margin: 1rem;
padding: 0;
}
ul.b li p::before {
content: "=>";
font-weight: bold;
position: relative;
left: -2.5rem;
}