首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >CSS样式:在定位之前?额外空间

CSS样式:在定位之前?额外空间
EN

Stack Overflow用户
提问于 2019-04-10 08:40:38
回答 1查看 173关注 0票数 0

小提琴在这里:https://jsfiddle.net/sgbotsford/d52zyp0t/72/

问题就在这里。当我使用a:之前,带负的左键时,它是有效的--它就像我想要的那样坐在页边空白处。这种额外的缩进是从哪里来的?

所需的行为是使段落和列表项具有相同的样式,除了浮动在左边距之外的=>。

我确信我最终可以进行足够的实验来破解一个解决方案,但现在我正试图从盒子模型的角度来理解这种行为。

HTML

代码语言:javascript
复制
<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

代码语言:javascript
复制
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;
    }
EN

回答 1

Stack Overflow用户

发布于 2019-04-10 14:46:51

您好,请检查一下,这对您真的很有帮助吗?我只需删除p标签text-indent并更改ul.b li p::在左侧位置之前添加text-indent in ul.b li p元素

代码语言:javascript
复制
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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55603153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档