如何在.right
保持在中心的同时将.centred
一直向右推? (它不需要使用flex,但我需要在移动视图上将.centred
保持在.right
之上
https://codepen.io/anon/pen/rjZLOv
<div class="flex">
<div class="centred">
<div class="a">asdfasdf</div>
<div class="b">asdfasdf</div>
</div>
<div class="right">asdfasfad</div>
</div>
.flex {
display: flex;
align-items: center;
justify-content: center;
}
.centred {
justify-content: center;
}
.right {
justify-content: flex-end;
}
答案 0 :(得分:1)
您可以.centred
inline-block
并使用父级text-align: center;
将其居中,然后向右浮动.right
。
.container {
width: 1024px;
margin: auto;
text-align: center;
}
.centred {
display: inline-block;
}
.right {
float: right;
}
<div class="container">
<div class="centred">
<div class="a">asdfasdf</div>
<div class="b">asdfasdf</div>
</div>
<div class="right">asdfasfad</div>
</div>
答案 1 :(得分:1)
你可以这样做:https://codepen.io/anon/pen/dNqXjo
代码:
.flex {
display: flex;
align-items: center;
justify-content: space-between;
}
.flex > * {
flex: 1;
}
.flex::before {
content: "";
flex: 1;
background: red;
}
这使得flex容器(.flex)中的项目使用flex。
然后我们添加另一个项目以使用左侧站点上的其余空间,以便将其余内容推送到右侧。
使用flex-basis
配置宽度。
答案 2 :(得分:1)
你几乎拥有它只需要margin-left
和方向基础:
.flex {
display: flex;
align-items: center;
flex-direction: column;
}
.centred {
}
.right {
margin-left: auto;
}