只是练习 CSS 中的 max-width
属性。在下面的代码中,即使在设置了 max-width: 960px;max-height: 200px;
可能是什么原因?请注意,我使用最大宽度/高度是因为我希望内部 div 根据浏览器窗口的大小进行缩放。
html,body {
margin: 0px;
height: 100%;
width: 100%;
left: 0px;
top: 0px;
background-color: rgba(173,192,241,1);
}
.wrapper {
height: 800px;
max-width: 960px;
margin-left: auto;
left: 0px;
top: 0px;
margin-right: auto;
position: relative;
}
.topimage {
max-width: 960px;
max-height: 200px;
background-color: rgba(255,0,0,1);
}
<div class="wrapper">
<div class="topimage">
</div>
</div>
最佳答案
你需要宽度和高度。
Max-width 不会分散你的 div。
使用宽度:100%,最大宽度:960px;
对于高度,您需要在其中包含一个内容或放置 height:100px,例如。
关于html - 内部div的最大宽度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37912703/