可以使用以下 CSS 代码实现容器居中:

.container { display: flex; justify-content: center; align-items: center; }

这会使容器在水平和垂直方向上都居中。可以将上述代码应用于你想要居中的容器的父级元素。

.input-box { display: flex; align-items: center; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 5px; padding: 5px; }

CSS 容器居中实现方法 | 使用 flexbox 轻松实现水平垂直居中

原文地址: https://www.cveoy.top/t/topic/n6gs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录