html - CSS Flex 一个孩子顶另一个底
问题描述
我想做的是让a
元素在顶部和button
底部,没有使用absolute
或fix
位置,只是flex
有什么解决方案吗?已经button
在底部但title
不在顶部:
.all {
display: flex;
height: 300px;
}
.element1 {
width: 50%;
background: blue;
}
.element2 {
background: red;
width: 50%;
}
#details {
height: 100%;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: self-end;
}
#details a {
width: 100%;
}
#details button {
width: 100%;
height: 50px;
}
<div class="all">
<div class="element1"></div>
<div class="element2">
<div id="details">
<a>title</a>
<button>Add TO Cart</button>
</div>
</div>
</div>
解决方案
您可以通过使用flex-direction: column;
on来实现,#details
然后使用以下方法分隔子级justify-content: space-between;
:
.all {
display: flex;
height: 300px;
background: gray;
}
.element1 {
width: 50%;
background: blue;
}
.element2 {
background: red;
width: 50%;
}
#details {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
#details a {
width: 100%;
}
#details button {
display: block;
width: 100%;
height: 50px;
}
<div class="all">
<div class="element1"></div>
<div class="element2">
<div id="details">
<a>title</a>
<button>Add TO Cart</button>
</div>
</div>
</div>
推荐阅读
- android - org.apache.http.params 在我有 sdk 版本 25 的地方被弃用了?
- javascript - 对象的 JavaScript array.push()
- azure - 将 Microsoft Graph 权限分配给 Azure 托管服务标识
- android - getUserMedia 是否适用于 Android 应用程序的 ionic-webview?
- javascript - 日期范围没有克隆
- deployment - 将 Kentico CMS 安装为 3 层
- javascript - 将字符串数组转换为 JSON 属性中的对象数组
- java - 如何使用 java 8 过滤掉空值或空值?
- jquery - DataTables.net 宽度不适用于排序
- php - Firebase (FCM) 响应弄乱了我的响应