在这里 fiddle :https://jsfiddle.net/sgbotsford/d52zyp0t/72/
<li>
中额外的首行缩进来自哪里?使用 => : 在内容之前?
问题来了。在我无法控制的情况下,将段落标签放在列表元素中。当我使用 :before 时,左边是负数,它起作用了——它就像我想要的那样位于边缘。但是在我使用 :before 的地方增加了文本缩进。这个额外的缩进是从哪里来的?
期望的行为是让段落和列表项具有相同的样式,除了 => float 在左边距之外。
我确信我最终可以进行足够多的实验来破解一个解决方案,但现在我正试图从盒子模型的 Angular 来理解这种行为。
一个答案建议从 <p>
中删除文本缩进标签这导致冲洗 <p>
和 <li>
上的缩进较小
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;
}
最佳答案
Hi Can you please check it's really helpfull for you I just Remove p tag text-indent and change ul.b li p::before left position Add text-indent in ul.b li p element
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-align: justify;
hyphens: auto;
word-break: break-word;
padding: 5px;
}
ul {
list-style-type: none;
margin: 1rem;
padding: 0;
}
ul.b li p::before {
content: "=>";
font-weight: bold;
position: relative;
left: -10px;
}
ul.b li p {
text-indent: -22px;
}
.bluetable {
background-color: #9FF;
border: 2px solid black;
}
td {
margin: 14rem;
border: 1px dashed green;
}
关于html - CSS 样式 :before position? 额外空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55603153/