我一直想弄清楚如何垂直重新排列两个项目。我记得刚才用flexbox做了类似的事情并且已经找到了再次做的方法,但是当我尝试实现flexbox并给项目订单号时没有任何反应。我需要的是.trail-title
堆叠在.trail-items
以下。
如何让他们使用flexbox垂直切换位置?
这是我创建的JSFidde: https://jsfiddle.net/tb1sv7n8/15/
#flash-breadcrumbs {
display: flex;
flex-wrap: wrap;
-webkit-flex-flow: column wrap;
flex-flow: column wrap;
flex-direction: column;
}
.trail-items {
order: 1;
height: 1em;
}
.trail-title {
height: 1em;
}
.breadcrumbs,
.breadcrumbs a {
color: #544f47;
font-size: .9em;
font-weight: normal;
}

<nav id="flash-breadcrumbs" class="breadcrumb-trail breadcrumbs">
<div class="tg-container">
<h1 class="trail-title">Title of Article: The Love of This</h1>
<ul class="trail-items">
<li class="trail-item"><span>This here is the trail: The Love of This</span></li>
</ul>
</div>
</nav>
&#13;
答案 0 :(得分:2)
将flex-direction
值从column
更改为column-reverse
要比为每个弹性项应用不同的order
值要简单得多。但这仅适用于flex项目,因此您应将其直接应用于.tg-container
。优化了CSS:
#flash-breadcrumbs .tg-container {
display: flex;
-webkit-flex-flow: column-reverse wrap;
flex-flow: column-reverse wrap;
}
.trail-items,
.trail-title {
height: 1em;
}
.breadcrumbs,
.breadcrumbs a {
color: #544f47;
font-size: .9em;
font-weight: normal;
}
<nav id="flash-breadcrumbs" class="breadcrumb-trail breadcrumbs">
<div class="tg-container">
<h1 class="trail-title">Title of Article: The Love of This</h1>
<ul class="trail-items">
<li class="trail-item"><span>This here is the trail: The Love of This</span></li>
</ul>
</div>
</nav>
答案 1 :(得分:1)
您需要将flex
应用于.tg-container
div,因为它是两者的父级,并将order
属性的值更改为-1
.trail-items
div,然后将其置于.trail-title
:
.tg-container {
display: flex;
/*flex-wrap: wrap; not necessarry*/
-webkit-flex-flow: column wrap;
flex-flow: column wrap; /* this is enough */
/*flex-direction: column; not necessarry*/
}
.trail-items {
order: -1; /* modified */
height: 1em;
}
.trail-title {
height: 1em;
}
.breadcrumbs, .breadcrumbs a {
color: #544f47;
font-size: .9em;
font-weight: normal;
}
&#13;
<nav id="flash-breadcrumbs" class="breadcrumb-trail breadcrumbs">
<div class="tg-container">
<h1 class="trail-title">Title of Article: The Love of This</h1>
<ul class="trail-items">
<li class="trail-item">
<span>This here is the trail: The Love of This</span>
</li>
</ul>
</div>
</nav>
&#13;
答案 2 :(得分:1)
您使用了错误的CSS选择器:Flex容器必须为#flash-breadcrumbs .tg-container
- 在您的代码.tg-container
中,因为#flash-breadcrumbs
的子项是唯一的弹性项...
然后您可以根据需要添加order
设置:
#flash-breadcrumbs .tg-container {
display: flex;
flex-wrap: wrap;
-webkit-flex-flow: column wrap;
flex-flow: column wrap;
flex-direction: column;
}
.trail-items {
order: 1;
height: 1em;
}
.trail-title {
order: 2;
height: 1em;
}
.breadcrumbs,
.breadcrumbs a {
color: #544f47;
font-size: .9em;
font-weight: normal;
}
<nav id="flash-breadcrumbs" class="breadcrumb-trail breadcrumbs">
<div class="tg-container">
<h1 class="trail-title">Title of Article: The Love of This</h1>
<ul class="trail-items">
<li class="trail-item"><span>This here is the trail: The Love of This</span></li>
</ul>
</div>
</nav>