html - 无法使 flex 显示工作

标签 html css alignment flexbox

我会用一张图片向你展示我想做的事情,让你看得更清楚...

1: header 与内容占用相同的空间。

2:“aside-1”、“content”和“aside-2”在顶部水平对齐。

#flex{
  display:flex;
  flex-wrap: wrap;
}

aside{
  max-width: 300px;
}
<div id='flex'>
  <header id='header'>
  </header>
  
  <aside id='aside-1'>
  </aside>
  
  <content id='content'>
  </content>
  
  <aside id='aside-1'>
  </aside>
  
 </div>

附言如果我在标题的左侧和右侧放置另外 2 个 div,我可以完成...这将占用与标题相同的空间...但我想在没有那个 div 的情况下实现它。

我想要 Css/html 的解决方案。

谢谢!

最佳答案

我创建了一个 fiddle ,看看它。 我希望这个能帮上忙。 没有多余的 div。

* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

#flex {
  display: flex;
  flex-direction: column;
  background: #ccc;
  width: 100%;
}

#flex .holder {
  display: flex;
  flex-direction: row;
      margin-top: 18px;
}

#flex .holder > * {
  flex: 1;
}

aside {
  max-width: 300px;
}

#header {
  background: #00a652;
  margin-top: -18px;
}

#aside-1 {
  background: #f7941d;
}

#aside-2 {
  background: #00adef;
}

#content {
  background: #ed1b24;
}
<div id='flex'>


  <div class="holder">
    <aside id='aside-1'>
      aside01
    </aside>

    <content id='content'>
      <header id='header'>
        header
      </header>
      Content
    </content>

    <aside id='aside-2'>
      aside02
    </aside>
  </div>

</div>

Click for fiddle Demo

关于html - 无法使 flex 显示工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42200854/

相关文章:

javascript - jquery addClass 函数在不抛出任何错误的情况下无法正常工作

javascript - 引导 Accordion 默认在桌面上显示,默认隐藏移动

css - 如何在不使用 CSS 添加新类的情况下对齐 DIV 中的图像

css - 如何在一页网站中居中放置两个 div?

html - 如何加载外部 jQuery 模板

javascript - Uncaught ReferenceError : google is not defined (index):21 initialize ( Google Maps API )

javascript - 完全适合 DIV 中的 bootstrap glyphicon,保持响应质量

html - 无论内容多少,如何使我的侧边栏与页脚对齐?

css - 空白 : nowrap vs white-space: normal why is the effect on floating elements so big?

javascript - 我怎样才能让事件多次触发。