Flex 订单属性未按预期工作

Ama*_*nda 1 html css flexbox

我试图得到“通心粉和奶酪真的很好吃!” 在“网站的主要内容”下方。

#content {
  padding: 0;
  background: 0;
  float: none;
  width: auto;
}
.heading {
  display: flex;
  display: -webkit-flex;
  flex-direction: column;
  -webkit-flex-direction: column;
}
#content h1 {
  text-align: left;
  width: 100%;
  float: none;
  margin: 0 0 10px;
  font: 2.538em/1.3em;
  color: #393939;
}
#content .text {
  order: 1;
}
Run Code Online (Sandbox Code Playgroud)
<div id="content">
  <div class="heading">
    <h1>Mac and Cheese</h1>
    <div class="text">
      <p>Mac and cheese is really yum!</p>
    </div>
  </div>
  <div class="main-content">
    The main content of the site</div>
</div>
Run Code Online (Sandbox Code Playgroud)

http://codepen.io/anon/pen/KMPydJ

任何帮助表示赞赏 - 谢谢!

Mic*_*l_B 7

CSSorder属性仅适用于兄弟姐妹。

在您的代码中,您试图重新定位.text,它是弹性项目 ( .heading)的子项,以出现在 之后.main-content

嗯,.heading而且.main-content是兄弟姐妹。但是.text就像侄女一样.main-content,所以order属性不起作用。

一旦.text成为.main-content兄弟姐妹,您就可以实现您想要的排序。

在下面修改后的代码中,我删除了您的.heading元素。现在h1,.text.main-content都是兄弟姐妹。

#content {
  display: flex;
  flex-direction: column;
}
h1 {
  margin: 0 0 10px;
  font: 2.538em/1.3em;
  color: #393939;
}
.text {
  order: 1;
}
Run Code Online (Sandbox Code Playgroud)
<div id="content">
  <h1>Mac and Cheese</h1>
  <div class="text">
    <p>Mac and cheese is really yum!</p>
  </div>
  <div class="main-content">The main content of the site</div>
</div>
Run Code Online (Sandbox Code Playgroud)

order此处了解有关该物业的更多信息:https : //stackoverflow.com/a/36118012/3597276