我有下面的代码。
在.container
上设置
display:flex;
flex-direction: column;
使我的previous
和next
箭头在容器items
之前和之后移动。伸缩方向仍然行是行不通的。
.container {
margin: 0;
position: relative;
overflow: hidden;
border: 1px solid green;
display: flex;
flex-direction: column;
}
.items {
left: 0;
top: 0;
display: flex;
flex-direction: row;
padding: 0.5rem 0;
position: relative;
margin: 2px;
}
.item {
align-items: center;
display: flex;
height: 60px;
justify-content: center;
margin: 2px;
}
.item>* {
cursor: pointer;
display: flex;
max-height: 100%;
}
.item img {
display: block;
max-height: 100%;
}
.previous::before,
.next::before {
color: #9e9e9e;
font: 400 1.5rem/1 iconfont !important;
speak: none;
text-transform: none !important;
}
<div class="container">
<div class="previous">S</div>
<div class="items">
<div class="item">
<a href="#"><img src="https://via.placeholder.com/50"></a>
</div>
<div class="item">
<a href=""><img src="https://via.placeholder.com/50"></a>
</div>
<div class="item">
<a href=""><img src="https://via.placeholder.com/50"></a>
</div>
<div class="item">
<a href=""><img src="https://via.placeholder.com/50"></a>
</div>
</div>
<div class="next">S</div>
</div>
答案 0 :(得分:3)
实际上,您需要从flex-direction: column
中删除.container
,因为您正试图通过将箭头插入项目中来创建一行
.container {
margin: 0;
position: relative;
overflow: hidden;
border: 1px solid green;
display: flex;
align-items: center
}
.items {
left: 0;
top: 0;
display: flex;
padding: 0.5rem 0;
position: relative;
margin: 2px;
flex: 1;
background: lightblue;
justify-content: center
}
.item {
align-items: center;
display: flex;
height: 60px;
justify-content: center;
margin: 2px;
}
.item>* {
cursor: pointer;
display: flex;
max-height: 100%;
}
.item img {
display: block;
max-height: 100%;
}
.previous::before,
.next::before {
color: #9e9e9e;
font: 400 1.5rem/1 iconfont !important;
speak: none;
text-transform: none !important;
}
<div class="container">
<div class="previous">S</div>
<div class="items">
<div class="item">
<a href="#"><img src="https://via.placeholder.com/50"></a>
</div>
<div class="item">
<a href=""><img src="https://via.placeholder.com/50"></a>
</div>
<div class="item">
<a href=""><img src="https://via.placeholder.com/50"></a>
</div>
<div class="item">
<a href=""><img src="https://via.placeholder.com/50"></a>
</div>
</div>
<div class="next">S</div>
</div>