作者:豪哥帅366 | 来源:互联网 | 2023-01-09 10:19
我正试图在班级车上应用绝对定位.我希望它放在矩形内的左上角.当前行为被放置在页面的左上角,这是我不想要的.据我所知,绝对元素必须位于其祖先之内.
body {
padding: 25px;
}
.car {
position: absolute;
}
#rectangle {
/* display: inline-block;
position: absolute;
top: 150px;
left:25px; */
width: 3324px;
height: 5112px;
background-color: #00b3ee;
}
#intro {
/* position: absolute;
top: 800px;
left:25px; */
border: solid 1px;
padding: 10px;
}
1> Jesse..:
添加position: relative
到#rectangle
类.绝对定位是相对于第一个定位的祖先.