html - CSS - 跨度 bg-color 与文本高度相同

标签 html css

p {
  font-size: 60px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"/>

<p>Hill <span class="bg-primary text-light">Side</span></p>

我希望 span 标签的高度与边 text 的高度相同,这可能吗?

最佳答案

您可以将 span.bg-primary 元素设置为 display as inline-block,然后您可以使用 行高

.bg-primary {
    line-height: 43px;
    display: inline-block;
}

p {
  font-size: 60px;
}
.bg-primary {
    line-height: 43px;
    display: inline-block;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"/>

<p>Hill <span class="bg-primary text-light">Side</span></p>

关于html - CSS - 跨度 bg-color 与文本高度相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51296611/

相关文章:

html - 这个按字母顺序排列的 css 选择器是什么意思?

php - 注册不插入数据

css - 如何赋予 gridview 标题行 3-D 外观?

javascript - 想知道在以下代码行中传递了什么变量(查询)

javascript - 应该每秒重复一次的函数立即发生

html - 在 R 中解析 HTML 文件

css - 在相对容器位置内对齐中心

css - iPad 条件 CSS 不工作

css - Chrome 改变内联样式

html - css3 边框图像