.parent {
position: relative;
background-color: #F00;
}
.child {
position: absolute;
top: 100%;
left: 0;
background-color: #00F;
}
transform: translateY(100%)
来实现此功能。
translateY() CSS 函数用于在平面上垂直移动元素。该变换特点是通过一个<length>
来定义其垂直方向的移动距离。translateY(ty)
是快捷方式,等同于 translate(0, ty)
。
.parent {
position: relative;
background: red;
width: 50%;
height: 50vh;
}
.child {
position: absolute;
left: 0;
bottom: 0;
background: blue;
height: 100px;
width: 100px;
transform: translateY(100%);
}
<div class="parent">
<a href="#">Parent</a>
<div class="child">
<a href="#">Child</a>
</div>
</div>
transform: translateY(-100%);
这样做是因为该值是针对子元素而不是父元素的。 - Dem Pilafiantransform: translateY(-100%);
这个方法之所以有效,是因为该值是针对子元素而不是父元素的。 - undefined
<br>
,并根据需要设置此换行符的填充和边距? - Atilla Arda Açıkgöz