html - 如何在边框内居中文本?
问题描述
这就是我的样式表中的内容
.box {
background-color: red;
color: white;
text-align: center;
border: 1px solid white;
font-family: Arial;
height: 30px;
}
解决方案
您可以使用 flex 或其他时髦的样式 - 但最简单的方法是使用设置为与容器高度相同的行高。
.box {
background-color: red;
color: white;
text-align: center;
border: 1px solid white;
font-family: Arial;
height: 30px;
line-height: 30px
}
<div class="box">This is centered text</div>
推荐阅读
- r - 使用 R 中的 data.table 进行分组条件过滤
- postgresql - 在 PostgreSQL 中使用数组或 json 格式化字符串列
- reactjs - jss-snapshot-serializer:jss 嵌套选择器或@media 查询不会添加到 json 快照 (JEST)
- python - 在 Pandas Dataframe 中获取具有非零列的前 11 行
- javascript - 将 (number | number[]) 转换为 number[]
- git - 如何使用 git 忽略自动生成的文件?
- microsoft-teams - 在团队桌面、Web 和移动应用程序中呈现 AdaptiveCard 的差异,其中列样式未在前两个应用程序中应用。一个错误?
- android - Mantra 生物识别设备在扫描后无法获取数据(Android 集成)
- javascript - 新添加的元素在js中效果不好,为什么?
- snowflake-cloud-data-platform - 雪花函数创建