css:最小宽度和最小高度不适用于跨度?

css: min-width and min-height not working for span?

我试图将 <span> 部分强制设置为特定的宽度和高度。据我了解,css min-widthmin-height 应该处理这个问题。

然而它不起作用:live example

我还尝试为 body and/or html and/or 添加 css 属性,例如 height:100%min-height:100% <span> 标签,如其他类似问题的答案所建议,或使用 <div> 而不是 <span>,或使用 display:blockdisplay:inline-block,但 none 似乎解决了问题。

您应该为跨度设置 display:inline-blockdisplay:block。因为 span 的默认值为 display:inline。无法为 inline 个元素设置 heightwidth

#test {
  display:inline-block;
  min-width: 300px;
  min-height: 100px;
  background-color: #fa0;
}
<span id='test'>Hello</span>

内联元素不能使用高度和宽度。 使用 div 而不是 span 标签或在 div 元素中使用 span 标签。