【发布时间】:2022-11-16 22:05:13
【问题描述】:
我有一个基本的 html 标记,我正在尝试使用最小的 html 包装器来实现设计。
底部的 button 不应该对齐,它应该始终留在底部。
所以我的目标是不添加更多的 html 包装器,使用 flex,强制一个 flex 项目(button)放到下一行。 block title 留在图片旁边。
你可以明白我的意思是在移动断点上检查它。
这是flex-wrap: wrap的截图
如您所见,在第一个示例中,按钮应位于底部,但 block title 被放到下一行,而在第二个示例中 (flex-wrap: wrap) block title 位置正确,但按钮不正确在底部。
这是sandbox link和代码示例
body {
margin: 0;
padding: 0;
}
.container {
background-color: grey;
overflow: auto;
padding: 20px;
align-items: center;
display: flex;
position: relative;
column-gap: 15px;
flex-wrap: wrap;
/* //try nowrap */
width: 100%;
}
.logo-image {
align-self: flex-start;
}
.headline {
color: white;
}
.text {
color: white;
font-size: 16px;
margin-bottom: 20px;
}
.btn {
display: flex;
width: 100%;
}
button {
align-items: center;
background-color: black;
color: white;
flex: 0 0 100%;
justify-content: center;
margin: 0;
}
<div class="container">
<img src="download.png" width="50px" class="logo-image" alt="img" />
<span class="content">
<h4 class="headline">
Block Title
</h4>
<p class="text">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
aliquid sit, cupiditate
</p>
</span>
<div class="btn">
<button>link</button>
</div>
</div>
任何帮助将不胜感激
【问题讨论】: