我有 2 个 div,应用了最大宽度,按照我的意愿行事。其中一个的最大宽度为 900 像素,而其他的最大宽度为 820 像素,如果窗口尺寸变小,它们就会缩小。
<div id="componentWrapper">
<div class="thumbContainer"></div>
</div>
#componentWrapper{
position:absolute;
height:190px;
width:100%;
max-width:500px;
top:50%;
background:red;
margin-top:-85px;
}
#componentWrapper .thumbContainer{
top:0px;
left:0px;
height:180px;
max-width:420px;
margin-left:40px;
margin-right:40px;
background:green;
overflow:hidden;
}
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我现在尝试使用纯 CSS 将这个内部窗口居中。即使窗口的尺寸缩小到小于外部元素的当前宽度,它也需要保持居中。