gpt4 book ai didi

CSS:居中位置:固定

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

我遇到了一个(水平)居中固定位置元素的解决方案,如下所示:

element {
width: 200px;

position: fixed;
left: 0;
right: 0;
margin: 0 auto;
}

(其中 element 显然是要居中的元素)。

问题是这实际上是如何工作的?这是记录在案的行为吗?

很遗憾你不能垂直做同样的事情。

谢谢

最佳答案

您必须设置高度使其垂直居中并且 topbottom 必须为 0 同时将边距更改为此 margin:auto

试试这个:

element {
width: 200px;
height:10px;
position: fixed;
left: 0;
right: 0;
top:0;
bottom:0;
margin:auto;
}

关于CSS:居中位置:固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37405980/

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