溢出:自动 - 没有正确的填充&am​​p;保证金,铬

时间:2011-09-15 18:16:51

标签: overflow padding margin

问题是父div中没有​​正确的填充,而子div中没有​​右边距。我正在使用chrome。

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Template</title>
</head>
<body>
    <div style = "padding: 50px; overflow: auto; width: 300px; height: 300px; background-color: red;">
        <div style = "width: 500px; height: 500px; background-color: green;"></div>
    </div>
    <hr />
    <div style = "overflow: auto; width: 300px; height: 300px; background-color: red;">
        <div style = "margin: 50px; width: 500px; height: 500px; background-color: green;"></div>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我找到了填充的解决方案,遗憾的是它不适用于边距:

.container {
  overflow: auto;
  width: 300px;
  height: 150px;
  background-color: red;
}
.padding {
  float: left;
  padding: 50px;
}
.content {
  width: 500px;
  height: 500px;
  background-color: green;
}
<div class="container">
  <div class="padding">
    <div class="content"></div>
  </div>
</div>