gpt4 book ai didi

css - 从 flexbox 居中的 div 中删除全宽

转载 作者:行者123 更新时间:2023-11-28 09:47:27 26 4
gpt4 key购买 nike

如何从这个 flexbox 居中的 div 或其子元素中移除整个宽度?

即。这个:

enter image description here

应该是:

enter image description here

.main {
color: white;
background: blue;
position: relative;
height: 300px;
padding: 10px;
}

.wrapper {
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
position: absolute;
width: calc(100% - 20px);
height: calc(100% - 20px);
}

.wrapper p {
color: #000;
background: lightgrey;
}
<div class="main">
<div class="wrapper">
<p>Please press Enter to continue installation</p>
</div>
<p>Welcome to Windows 95</p>
</div>

最佳答案

您可以将 margin: 0 auto 设置为 .wrapper 中的 p 元素:

.main {
color: white;
background: blue;
position: relative;
height: 300px;
padding: 10px;
}
.wrapper {
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
position: absolute;
width: calc(100% - 20px);
height: calc(100% - 20px);
}
.wrapper p {
color: #000;
background: lightgrey;
margin: 0 auto;/*add margin 0 auto*/
}
<div class="main">
<div class="wrapper">
<p>Please press Enter to continue installation</p>
</div>
<p>Welcome to Windows 95</p>
</div>

关于css - 从 flexbox 居中的 div 中删除全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26810136/

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