html - 在 li 标签中显示空格

标签 html css

我有下面的 HTML 代码

ul {
    margin: 0;
    padding: 0;
    display: flex;
}

ul li {
    list-style: none;
    color: #484848;
    font-size: 80px;
}
<ul>
  <li>A</li>
  <li>B</li>
  <li>C</li>
  <li> </li>
  <li>E</li>
</ul>

我期待如下结果

ABC E

但相反,我越来越喜欢

ABCE

我不能使用  ,因为在我的工作中我正在迭代一个可能类似于下面的数组

array = ['A', 'B', 'C', ' ', 'E'];

有人可以建议如何获取空白值的空白吗?

这是密码笔https://codepen.io/gs650x/pen/mdmWOMJ

最佳答案

您可以设置min-width: 1ch,其中1ch 表示1 个字符的宽度

ul {
    margin: 0;
    padding: 0;
    display: flex;
}

ul li {
    list-style: none;
    color: #484848;
    font-size: 80px;
    min-width: 1ch;
}
<ul>
  <li>A</li>
  <li>B</li>
  <li>C</li>
  <li> </li>
  <li>E</li>
</ul>

ch
Represents the width, or more precisely the advance measure, of the glyph "0" (zero, the Unicode character U+0030) in the element's font.

Source: MDN Web Docs

关于html - 在 li 标签中显示空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68389826/

相关文章:

javascript - 使用 XPath 选择包含特定文本的 LI 时遇到问题

jquery - CSS,jquery 水平对齐中的固定标题

html - 我怎样才能只在 div 中设置某些列的样式?

jQuery - 动画 css 背景大小?

javascript - 在添加新标记之前删除以前的标记

html - 将元素符号点添加到 Accordion HTML

javascript - 是否可以在div中获取当前高度偏移量?

jquery - 为什么 <select> 的样式在所有浏览器中不能以相同的方式工作?

javascript - 具有多个图像模态的页面在第一个模态之后不加载图像

html - 如何让绝对定位的 div 的 child 粘在其绝对定位的父级的底部?