gpt4 book ai didi

css - 如何将文本作为 CSS 内容属性垂直和水平居中?

转载 作者:太空宇宙 更新时间:2023-11-04 11:02:58 24 4
gpt4 key购买 nike

我想将文本作为 CSS3 内容属性垂直和水平居中。屏幕调整大小居中应该没有问题。

请检查代码:http://jsfiddle.net/epomschar/3pb3swwe/

    <div class="container"></div>

.container {
position: relative;
height: 200px;
width: 200px;
}
.container:after {
position: absolute;
content: 'Center me!';
top: 50%;
right: 0;
bottom: 0;
left: 0;
text-align: center;
transform: translateY(-50%);
}
.container:before {
position: absolute;
content: '';
top: 0;
right: 0;
bottom: 0;
left: 0;
color: white;
background-color: yellow;
border-radius: 50%;
width: 100%;
height: 100%;
}

解决方案:http://jsfiddle.net/epomschar/3pb3swwe/7/

最佳答案

只需删除 bottom: 0; 即可得到解决方案。

 

.container {
position: relative;
height: 200px;
width: 200px;
}
.container:after {
position: absolute;
content: 'Center me!';
top: 50%;
right: 0;
/* bottom: 0; REMOVE THIS LINE */
left: 0;
text-align: center;
transform: translateY(-50%);
}
.container:before {
position: absolute;
content: '';
top: 0;
right: 0;
bottom: 0;
left: 0;
color: white;
background-color: yellow;
border-radius: 50%;
width: 100%;
height: 100%;
}
<div class="container"></div>

关于css - 如何将文本作为 CSS 内容属性垂直和水平居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34176663/

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