html - 对齐两个元素的基线
问题描述
我有以下 HTML 和 CSS:
h1 {
display: inline-block;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div style="width:500px">
<h1>My Title</h1>
<span class="float-right">Text on the right border</span>
</div>
- 如何将右侧的文本与 h1 的基线对齐?
- 如何将右侧的文本对齐在 h1 文本的中间?
如果您知道我的意思,我不想做“像素圈地”并将行高调整为 17.533 像素。
解决方案
你可以像这样使用 Flexbox :)
更多关于 Flexbox 的阅读 -> https://css-tricks.com/snippets/css/a-guide-to-flexbox/
h1 {
display: inline-block;
}
div {
display:flex;
justify-content:center;
align-items:center;
justify-content: space-between
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div style="width:500px">
<h1>My Title</h1>
<span class="float-right">Text on the right border</span>
</div>
推荐阅读
- python - 将一个字典的内容与另一个字典的内容进行比较
- c++ - C++:我不能给出输入 - 怎么了?
- spring - 是否可以在 GraphQL 后端之上构建一个 rest api?
- linux - 鱼主题“bobthefish”不显示特殊符号
- laravel - Laravel 项目无法在本地环境中运行
- java - 生命周期片段卡在 onResume
- javascript - 仅在桌面上使用 socket.io 获取 xhr 轮询错误
- json - 如何在颤动中对这种类型的 json 进行排序?
- python - SQL 到 Django 查询集
- python - 使用 pandas 计算时间范围内的阻塞时间