为什么垂直对齐在CSS中不起作用

问题描述 投票:0回答:1

为什么垂直对齐:中间在我的代码中不起作用,即使我将显示更改为内联块 xo 文本不应该位于该容器的垂直中间 什么时候才能真正发挥作用?

<!DOCTYPE html>
<html>
<style>
 .container {
    height: 100px;
    background-color: pink;
}

.centered {
    display: inline-block; 
    vertical-align: middle;
}


</style>
<body>
    <div class="container">
        <p class="centered">xo</p>
    </div>
</body>
</html>
css alignment
1个回答
0
投票

将.container类的display属性设置为inline-block或flex。这是您的更新代码:

.container {
    height: 100px;
    background-color: pink;
    display: inline-block; or display: flex;
 }
© www.soinside.com 2019 - 2024. All rights reserved.