【发布时间】:2021-06-21 16:54:46
【问题描述】:
假设我有 3 个 div,grandParent、Parent 和 Child。虽然父母的标签在祖父母内,但使用位置:绝对;父级呈现在祖父级之外。 现在我有一个高度和宽度为 100% 的孩子,它呈现在祖父母之外。 如何强制子级仅在 grandParent 内渲染。我希望绿色 div 完全在红色 div 内。并且黄色 div 部分保留在红色 div 之外。
<html>
<head>
<style>
.grandParent {
width: 600px;
height: 700px;
background-color:red;
}
.parent {
position: absolute;
left: 0px;
top: 0px;
width: 360px;
height: 275px;
background-color: yellow;
border: 2px solid yellow;
transform: translate(417px, -88px) rotate(
0deg
);
}
.child {
height: 275px;
background-color: green;
}
</style>
</head>
</head>
</head>
<body>
<div class="grandParent">
<div class="parent">
<div class="child">
</div>
</div>
</div>
</body>
</html>
【问题讨论】:
标签: javascript html css