gpt4 book ai didi

css - 居中相关元素

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

我有一个相关按钮

button {
width: 305.4px;
height: 60px;
background: #E43B40;
margin-top: 109.5px;
margin-left: auto;
margin-right: auto;
display: inline-block;
cursor: pointer;
border: 0px;
outline: none;
font-family: Roboto Bold;
font-size: 16px;
color: #FFFFFF;
position: relative
}

我试图将它置于屏幕中央。但它卡在同一个地方,边距不影响它。该按钮的父元素为div,样式如下:

parent {
width: 100%;
height: 100%;
margin-top: 504px;
background-repeat: no-repeat;
background-color: #F8F8F8;
padding-bottom: 250px;
overflow: auto;
display: block;
}

这可能是什么原因造成的?演示是 here

最佳答案

html,
body {
height: 100%;
}
body {
margin: 0;
}
.button {
width: 305.4px;
height: 60px;
background: #E43B40;
display: inline-block;
cursor: pointer;
border: 0px;
outline: none;
font-family: Roboto Bold;
font-size: 16px;
color: #FFFFFF;
position: relative;
top: 50%;
transform: translateY(-50%);
}

.parent{
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-color: #F8F8F8;
text-align: center;
}
<div class="parent">
<button class="button" type="button">Button</button>
</div>

关于css - 居中相关元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37413429/

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