html - 即使尝试了各种方法也无法垂直居中文本
问题描述
我正在尝试将文本(链接)置于 div 内。我能够让它水平居中,但不能垂直居中。我尝试了很多方法,文本的垂直位置永远不会改变。Padding-top 和其他类似的方法只是增加白框的大小,不影响文本。
HTML
----------
<div className={styles.buttonBorder}>
<Link to={`/event/${id}`} className={styles.link}>Details</Link>
</div>
CSS
----------
.buttonBorder {
display: flex;
align-items: center;
height: 50px;
border: 10px solid;
border-image-slice: 1;
border-width: 5px;
border-image-source: linear-gradient(
90deg,
rgba(148, 88, 199, 1) 0%,
rgba(92, 62, 183, 1) 100%
);
background: linear-gradient(
90deg,
rgba(148, 88, 199, 1) 0%,
rgba(92, 62, 183, 1) 100%
);
}
.link,
.link:visited,
link:link,
link:active {
background: white;
text-decoration: none;
color: black;
text-align: center;
font-size: 18pt;
border: 0;
width: 150px;
height: 50px;
cursor: pointer;
transition-duration: 0.4s;
border: 1px solid black;
}
.link:hover {
background: transparent;
text-decoration: none;
color: white;
cursor: pointer;
}
解决方案
在 .link 类中添加以下样式
display:flex;
justify-content: center;
align-items: center;
推荐阅读
- javascript - 有没有一种方法可以在 sprite.svg 文件组件上应用 javascript?
- jenkins - 詹金斯并行调用从文件加载的外部函数
- spring-boot - 即使在 MqttConnectOptions 中将自动重新连接设置为 true,Eclipse Paho MqttClient 也无法重新连接
- influxdb - 从 influxdb 2.0 中删除数据
- sql - 同一张表的SQL递归查询
- docker - 如何重用 docker-compose 并启动并运行多个实例?
- python - 标称值的标签编码
- php - PHP 在 foreach 循环中简化 array_push
- c++ - 哪个代码在内存/时间复杂度上更有效
- java - 两个函数while和预期条件有什么区别