gpt4 book ai didi

html - 调整浏览器大小时文本居中

转载 作者:太空宇宙 更新时间:2023-11-04 07:54:34 25 4
gpt4 key购买 nike

我有两个 div 容器,用于在屏幕中创建 100% 的叠加层,第二个在屏幕中央创建一些文本。

我希望在调整页面大小时文本保持在屏幕中央。我在某些事件中显示和隐藏容器。

   #container
{
background-color: rgba(0, 0, 0, 1);
display: none;
height: 100%;
width: 100%;
z-index: 999;
position: absolute;
}
#text
{
bottom: 0;
left: 0;
position: fixed;
right: 0;
text-align:center;
top: 50%;
}
    <div id="container">
<div id="text">some text here</div>
</div>

最佳答案

如果您正在寻找垂直对齐的目的。转到 display: table 属性

#container {
background-color: rgba(0, 0, 0, 1);
display: table;
height: 100%;
width: 100%;
position: absolute;
}

#text {
text-align: center;
color: #ffffff;
display: table-cell;
vertical-align: middle;
}
<div id="container">
<div id="text">some text here</div>
</div>

关于html - 调整浏览器大小时文本居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47456137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com