gpt4 book ai didi

HTML - 居中固定元素并提供父元素的宽度

转载 作者:太空宇宙 更新时间:2023-11-03 23:31:12 24 4
gpt4 key购买 nike

我想将一个固定的 div 在其父元素中居中。固定 div 的宽度应具有其父级的宽度。但是它不起作用,有什么问题吗?

js fiddle

HTML

<div class="container">
<div class="wrap">
<div class="center" >
centered
</div>
</div>
</div>

CSS

.container {
position: relative;
width: 300px;
height: 400px;
border:solid;
margin-right: auto;
margin-left: auto;
padding-left: 15px;
padding-right: 15px;
}

.wrap {
height: 800px;
width: 100%;
position: relative;
text-align: center;
}

.center{
background: red;
position: fixed;
bottom: 100px;
width: inherit;
}

最佳答案

改变.wrap的宽度:

.wrap {
height: 800px;
width: inherit;
position: relative;
text-align: center;
}

关于HTML - 居中固定元素并提供父元素的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25269271/

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