如果设置了 child min-with,则防止 div 崩溃

Prevent div collapsing if child min-with set

我有以下标记:

<html>
<head>
    <style>
        html,
        body {
            margin: 0;
            width: 100%;
            background: #000;
        }

        .wrapper {
            min-width: 1000px;
            background: #f00;
            height: 300px;
        }
    </style>
</head>
<body>
    <div class="problem-div">
        <div class="wrapper"></div>
    </div>
</body>
</html>

当我调整浏览器大小时 window DIV.problem-div 获取正文,html 或视口(我不太清楚)。我需要的是使 div 获取其子项 (.wrapper) 的宽度,而不设置其最小宽度或使其绝对定位。可能吗?

Divs 是块级元素,其宽度始终为 100%。将显示 属性 设置为 inline-block,这应该会让你得到想要的结果。

.problem-div {
    display: inline-block;
}