[英]How to use Order in a Flexbox
I have this section that is flexbox with a flex-direction: column, and i want to put the title as the first element only in the mobile view.我有这个部分是 flexbox 与 flex-direction: 列,我想把标题作为第一个元素只放在移动视图中。
But i don't know how to use the order property to make this work.但我不知道如何使用 order 属性来完成这项工作。
<section class="section section--team">
<img
class="section--team__image"
src="./imagens/requite.jpeg"
alt="Time da Instalura" />
<div class="section--team__content">
<h1 class="section--team__title">Nossa Equipe</h1>
<p class="section__text section--team__text">
O instalura foi criado por uma equipe compentente utilizando que há de
mais moderno na tecnologia, mas sempre primando pela experiência do
usuário.
</p>
<p class="section__text section--team__text">
Venha conhecer nossa equipe. Quem sabe até trabalhar conosco!
</p>
<ul class="section--team__links">
<li><i class="fas fa-users"></i> <a> Conheça nossa equipe </a></li>
<li>
<i class="fas fa-project-diagram"></i> <a> Trabalhe com a gente </a>
</li>
</ul>
</div>
</section>
My Stylesheet of the Section and the elements.我的部分样式表和元素。 Now, i think it will be more clear to help me
现在,我认为帮助我会更清楚
&--team {
display: flex;
justify-content: space-around;
align-items: flex-start;
padding-top: 3rem;
padding-left: 3rem;
padding-right: 3rem;
background-color: $ocean-blue;
@media (min-width: 320px) and (max-width: 480px) {
flex-direction: column;
align-items: center;
justify-content: center;
}
&__content {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
height: 100%;
}
&__title,
&__links li {
a {
color: $white;
margin-left: 2px;
}
.fa-users,
.fa-project-diagram {
color: $blue-lighten;
}
}
&__text,
&__links {
margin-left: 2rem;
@media (min-width: 320px) and (max-width: 480px) {
margin-left: 0rem;
}
}
&__title {
color: $white;
font-size: $font-xl;
align-self: center;
margin-bottom: $margin-sm;
}
&__text {
margin-bottom: $margin-xs;
}
&__links {
margin-top: $margin-xs;
li {
margin-top: $margin-xs;
}
}
&__image {
height: 10rem;
margin-bottom: 3rem;
border-radius: 3px;
}
}
Flexbox ordering happens with the flex-direction
and flex-wrap
properties. Flexbox 排序发生在
flex-direction
和flex-wrap
属性中。 Flex-direction
specifies the direction of the main axis. Flex-direction
指定主轴的方向。 It can take the following values:它可以采用以下值:
row
(default) main axis: left to right row
(默认)主轴:从左到右row-reverse
main axis: right to left row-reverse
主轴:从右到左column
main axis: top to bottom column
主轴:从上到下column-reverse
main axis: bottom to top column-reverse
主轴:从下到上Flex-wrap
defines if flex items are laid out in a single line or wrap to multiple lines. Flex-wrap
定义了弹性项目是在单行中布局还是换行到多行。 It also controls the direction of the cross axis.它还控制交叉轴的方向。 It can have three values:
它可以有三个值:
nowrap
(default) lays out flex items in a single line; nowrap
(默认)在一行中布置弹性项目; the cross axis stands in the default positionwrap
lays out flex items in multiple lines; wrap
以多行布局弹性项目; the cross axis stands in the default positionwrap-reverse
lays out flex items in multiple lines; wrap-reverse
以多行布局弹性项目; the cross axis is reversedFlex items are displayed in the same order as they appear in the source document by default.
默认情况下,弹性项目的显示顺序与它们在源文档中的显示顺序相同。 The
order
property can be used to change this ordering.order
属性可用于更改此排序。
Here is an example of using flexbox's order
property:下面是一个使用 flexbox 的
order
属性的例子:
.flex-container { padding: 0; margin: 0; list-style: none; display: flex; flex-flow: row wrap; }.flex-item:nth-of-type(1) { order: 3; }.flex-item:nth-of-type(2) { order: 4; }.flex-item:nth-of-type(3) { order: 1; }.flex-item:nth-of-type(4) { order: 5; }.flex-item:nth-of-type(5) { order: 2; }.flex-item { background: tomato; padding: 5px; width: 100px; height: 100px; margin: 5px; line-height: 100px; color: white; font-weight: bold; font-size: 2em; text-align: center; }
<ul class="flex-container"> <li class="flex-item">1</li> <li class="flex-item">2</li> <li class="flex-item">3</li> <li class="flex-item">4</li> <li class="flex-item">5</li> </ul>
FYI the flex-flow
property is a shorthand property for flex-direction
and flex-wrap
.仅供参考
flex-flow
属性是flex-direction
和flex-wrap
的简写属性。
You can check out this MDN web doc for diving deeper.您可以查看此 MDN web 文档以深入了解。
Hope it helps:)希望能帮助到你:)
You can use this code in Flexbox您可以在 Flexbox 中使用此代码
body { margin: 0; } /*************** MOBILE *************/.container { display: flex; flex-direction: column; height: 200px; } div.orange { background-color: orange; } div.blue { order: -1; background-color: aqua; } div.green { background-color: lightgreen; }.container>div { width: 100%; flex: 1; display: flex; align-items: center; justify-content: center; } /***************************/ @media screen and (min-width:800px) {.container { flex-wrap: wrap; } div.orange { flex-basis: 100%; width: 33%; } div.blue { flex-basis: 100%; width: 33%; order: 0; } div.green { flex-basis: 100%; width: 33%; } }
<div class="container"> <div class="orange">1</div> <div class="blue">2</div> <div class="green">3</div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.