2016-03-03 113 views
2

你能帮助以下吗?Basis简单的Flex布局

<div id="stage" class="flex-container"> 
      <header> 
       <b>Top content</b> 
      </header> 
      <aside> 
       Right 
      </aside> 
      <footer> 
       Footer 
      </footer> 
     </div> 

我想有22%的宽度和88%的高度,安装在右侧。 我希望有头开始88%的宽度和88%的高度安装到顶部,而页脚明显是:22高度和100%宽度安装到地板上;)

我一直在为这个问题而战现在一天。希望你能帮助我。

回答

0

父容器设置为一个显式的高度(例如400像素):

#stage { 
    height: 400px; 
} 

然后漂浮一边,彼此相邻头父DIV中(例如主),并应用一个clearfix到主要(例如搭配:后):

jsFiddle

另外,如果你希望你的布局是视口的高度的100%,您可以设置html和身体为100%,并给予#stage的100%的高度太:

html,body{ 
    100%; 
} 

#stage { 
    border: .125em solid; 
    height: 100%; 
} 

jsFiddle

+0

那就是proplem。我无法使用固定的高度或宽度。它完全依赖于屏幕尺寸/分辨率。 –

+0

然后参见解决方案二。 – symlink

1

AAAAH我只是找到了解决办法:很简单的,如果你问我。

body,html 
{ 
    height:100%; 
    width: 100%; 
    margin: 0; 
} 
#stage 
{ 
    height: 100%; 
    width: 100%; 
    display: flex; 
    flex-direction: column; 
    min-height: 100vh; 
} 
aside 
{ 
    background-color: red; 
    height: 88%; 
    position: absolute; 
    right: 0; 
    top: 0; 
    width: 12%; 
} 
footer 
{ 
    background-color: #ffc107; 
    bottom: 0; 
    color: #333; 
    height: 12%; 
    position: absolute; 
    width: 100%; 
} 
header 
{ 
    background-color: #3F51B5; 
    color: #fff; 
    height: 88%; 
    left: 0; 
    top: 0; 
    position:absolute; 
    width:88%; 
} 
+0

看起来不错。仅供参考,您不需要在#stage属性上显示:flex,flex-direction或min-height。 – symlink

+0

好的非常感谢 –