html - Flexbox:文本项 `font-size: 0' 并占用空间

标签 html css font-size flexbox

div { display: flex
    ; font-size: 0
    ; justify-content: space-between
    }

div > a { font-size: 10pt }

<div>
  Banana
  <a>Meat grinder</a>
  <a>Phone</a>
</div>

Live

font-size 设置为 0 时,为什么 Flexbox 文本项会占用空间?有没有办法解决它,例如文本项的选择器?假设我无法访问 HTML。

最佳答案

规范说:

4. Flex Items

Loosely speaking, the flex items of a flex container are boxes representing its in-flow contents.

Each in-flow child of a flex container becomes a flex item, and each contiguous run of text that is directly contained inside a flex container is wrapped in an anonymous flex item. However, an anonymous flex item that contains only white space (i.e. characters that can be affected by the white-space property) is not rendered, as if it were display:none.

因此,您观察到的这种行为是因为您的文本被包裹在一个匿名的 flex 元素中,即使您的文本因为 font-size: 0 而没有显示也是如此。

关于html - Flexbox:文本项 `font-size: 0' 并占用空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30021208/

相关文章:

javascript - 如何使用事件监听器动态分配 ID 到表单字段?

jquery - 有没有办法在每个 iframe 中获取父 css 链接 rel?

c# - 在 C# 中更改上下文菜单字体大小

html - 检测浏览器字体大小

javascript - 如何对此进行验证,在使用 javascript 或 jquery 发布之前必须选择至少 2 个选项

javascript - AngularJS 性能问题

javascript - Jquery 滑动开关 : Slide Button with Panel

html - 如何增加变换: scale radius when hover

c# - WPF 格式化文本 : Calculate font size to fill available height space

php - 我可以根据url更改iframe src吗?