html - 保持文本在容器内垂直居中
问题描述
我试图在 li 元素中保留一段呈现的文本,但我不知道该怎么做。我查找了说使用 line-height、vertical-align 和其他的教程,但是我无法让它们中的任何一个工作。
我试图在 li 元素中保持“Shop”文本垂直和水平对齐。我怎样才能做到这一点?
ul {
position: absolute;
padding-left: 0px;
width: 100%;
height: 15%;
top: 1%;
list-style-type: none;
background-color: #f8d7d7;
}
li {
float: left;
width: 10%;
height: 100%;
background-color: green;
text-align: center;
font-size: 2.5vw;
}
<ul>
<li>
Shop
</li>
</ul>
这是一个小提琴:
解决方案
将您的li
样式更新为
li {
width: 10%;
height: 100%;
background-color: green;
display: flex;
justify-content: center;
align-items: center;
font-size: 2.5vw;
}
签出片段
ul{
position: absolute;
padding-left: 0px;
width: 100%;
height: 15%;
top: 1%;
list-style-type: none;
background-color: #f8d7d7;
}
li{
width: 10%;
height: 100%;
background-color: green;
display: flex;
justify-content: center;
align-items: center;
font-size: 2.5vw;
}
<ul>
<li>
Shop
</li>
</ul>
显示:弯曲;证明内容:中心;对齐项目:居中;字体大小:2.5vw;}
推荐阅读
- docker - 如何在 gitlab runner 的 docker executor 中添加 ca.crt ie 证书?
- javascript - 如何在reactjs中从同一父组件获取不同布局的帖子
- c# - 无法在我的地图上的正确位置单击鼠标
- java - 如何将 1 个 JPanel 和 1 个自定义 JPanel 放入 JFrame
- c# - 图表的程序化创建及其图例的设置
- node.js - Heroku 上的 React 应用程序获取无效的主机标头
- python - 如何在 QGIS 的右上角设置 DockWidget?
- c# - 使用 Lambda C# 使用另一个列表更新对象列表中的属性
- c++builder - std::variant:为什么没有可行的重载 '=' 错误
- python - 如何使用 python 发送 REST API(Google Vision 的 API)请求?