如何对齐列出的项目符号文本?

How to align listed bullet point text?

提问人:Ripley E 提问时间:10/24/2023 更新时间:10/24/2023 访问量:33

问:

我有一个以图像为项目符号的项目符号列表,并按代码片段所示对其进行编码:

li::before {
  content: "";
  display: inline-block;
  height: 15px;
  width: 15px;
  background-size: contain;
  background-image: url('https://adp-com-prod.es.ad.adp.com/-/media/apps/wfn/images/rs_email_checklisticon-bullet.png?rev=f7aed74…&hash=2EB10B8B4C4FCB24BC37B1E501219BBB');
  background-repeat: no-repeat;
  margin-right: 7px;
  background-position: center center;
  vertical-align: middle;
}
ul {
  padding-left: 0;
  list-style: none;
}
       <ul class="voe-list">
                <li>
                  <strong>Simplicity.</strong> this is bullet number one with a longer sentence so it goes on the second line. Stay tuned for bullet number 2.
                </li>
                <li>
                  <strong>Compliance.</strong>this is bullet number one with a longer sentence so it goes on the second line.Stay tuned for bullet number 3. 
                </li>
                <li>
                  <strong>Flexibility.</strong>this is bullet number one with a longer sentence so it goes on the second line.Stay tuned for bullet number 4.
                </li>
              </ul>

如您所见,每个项目符号副本都没有对齐,第二行从复选标记开始的地方开始。我们有什么办法让它与第一行的第一个单词对齐吗?我可以添加左边距或左边距,但想看看是否有其他方法。

在默认的无序列表中,它确实对齐,因为列表样式位于标记中(请参见屏幕截图)

enter image description here

CSS HTML 列表

评论


答:

0赞 Nick Friesen 10/24/2023 #1

如果您添加负边距来抵消您添加的边距,您将获得所需的结果。

(我从网络上添加了一个项目符号图像,所以你可以看到列表布局正在按照你的意图工作)

li::before {
  content: "";
  display: inline-block;
  height: 15px;
  width: 15px;
  background-size: contain;
  background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAbFBMVEX///8AAAD4+PjV1dW8vLyrq6tJSUkxMTGMjIyCgoLf39+2traioqKJiYnw8PCurq4WFhZsbGyZmZnNzc1VVVXp6el0dHQ3NzdOTk5iYmLy8vIhISHIyMjj4+MZGRk+Pj4LCwspKSlaWlqVlZXFEy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+bT2SKfYP5Pd/rn69u9GCPi/6Or9FvbvKPkD98zYvyvIY40CdBeWCPN3dv2Be9dOr4fqSo/kwfz9h0XRO/xJtXWHZWH/HtKd7V2yS7t3yRIRERERERERERERERERERERERFRiH8bizuFfRy8ewAAAABJRU5ErkJggg==');
  background-repeat: no-repeat;
  margin-right: 7px;
  margin-left: -25px;
  background-position: center center;
  vertical-align: middle;
}
ul {
  padding-left: 0;
  list-style: none;
  margin-left: 25px;
}
<ul class="voe-list">
                <li>
                  <strong>Simplicity.</strong> this is bullet number one with a longer sentence so it goes on the second line. Stay tuned for bullet number 2.
                </li>
                <li>
                  <strong>Compliance.</strong>this is bullet number one with a longer sentence so it goes on the second line.Stay tuned for bullet number 3. 
                </li>
                <li>
                  <strong>Flexibility.</strong>this is bullet number one with a longer sentence so it goes on the second line.Stay tuned for bullet number 4.
                </li>
              </ul>

1赞 Nkemdi Anyiam 10/24/2023 #2

我理解你想做什么,但不是你如何改变要点。有了你所拥有的,你所要做的就是在每个的前面添加图像,所以它实际上是正确对齐的。li::before<li>

要修复它,请完全摆脱这种风格。您可以使用属性和 更改 的项目符号。li::before<ul>list-styleurl()

ul {
  /* padding-left: 0; */
  /* list-style: none; */
  list-style: url('https://adp-com-prod.es.ad.adp.com/-/media/apps/wfn/images/rs_email_checklisticon-bullet.png?rev=f7aed74…&hash=2EB10B8B4C4FCB24BC37B1E501219BBB');
}

这能解决您的问题吗?