Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何使用页面中心作为参照来对齐div元素?_Css_Html - Fatal编程技术网

Css 如何使用页面中心作为参照来对齐div元素?

Css 如何使用页面中心作为参照来对齐div元素?,css,html,Css,Html,所以我试图让一个元素与页面中心对齐一定的百分比 所以我试着用“中间”替换我通常从左边或右边输入的百分比 但是没有运气。这就是我在这里要做的: 我已经多次遇到这种情况,我的做法是: 1.将元素设置为绝对位置 2.使用百分比将元素设置为您想要的区域,以便在页面上居中,元素将为左:50%,左边距:-{width/2},但在本例中,元素为左:75%,左边距:-{width/2} .box { height:400px; width:400px; border:1px solid black; l

所以我试图让一个元素与页面中心对齐一定的百分比

所以我试着用“中间”替换我通常从左边或右边输入的百分比

但是没有运气。这就是我在这里要做的:


我已经多次遇到这种情况,我的做法是: 1.将元素设置为绝对位置 2.使用百分比将元素设置为您想要的区域,以便在页面上居中,元素将为左:50%,左边距:-{width/2},但在本例中,元素为左:75%,左边距:-{width/2}

.box {
 height:400px;
 width:400px;
 border:1px solid black;
 left: 75%;
 margin-left:-200px;
 position: absolute;
 }

我不知道你是否注意到了,但是
中心:25%什么也不做。您可能想要
左:50%
。如果你想让它移动25%,就让它
left:75%
这应该是您要找的。像这样:

.aboutcredit{
宽度:50px;
高度:50px;
背景色:黑色;
z指数:1;
位置:绝对位置;
左:75%;
最高:50%;
转换:翻译(-50%);
文本对齐:居中;
垂直对齐:中间对齐;
}

像这样吗?
.box {
 height:400px;
 width:400px;
 border:1px solid black;
 left: 75%;
 margin-left:-200px;
 position: absolute;
 }
.aboutcredit {
    z-index:-100000;
    left:50%;
    top:50%;
    transform:translateY(-50%) translateX(-50%);
    position:fixed;
    text-align:center;
    vertical-align:middle;
}