【发布时间】:2017-04-20 18:20:02
【问题描述】:
我使用 flex 布局已经有一段时间了。 主要是圣杯式布局,效果很好。
今天决定尝试创建相同的东西来帮助我更多地了解 flexbox。 但是将右侧的列用作侧边栏区域,将行用作徽标/标题和页面 div。
我已将其放入代码笔中,以便您自己查看标记代码。 我的问题是徽标/标题和主页在设置为行时会将列向下推。
<div class="wrapper">
<div class="nav">logo content and site banner goes here
<div class="spacer">
</div>
<div class="content">main page content goes here</div>
</div>
<div class="one">page index goes here</div>
<div class="two">twitter logo goes here</div>
<div class="three">chatbox goes here</div>
</div>
div {
box-sizing: border-box;
}
.wrapper {
border: 2px solid blue;
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: flex-end;
position: relative;
}
.nav {
flex-direction: row;
border: 2px solid green;
width: 100%;
height: 100px;
align-self: flex-start;
padding-left: 8px;
margin-bottom: 4px;
}
.spacer {
height: 140px;
width: 100%;
}
.content {
flex-direction: row;
border: 2px solid green;
height: 40px;
padding-left: 8px;
align-self: flex-start;
}
.one {
width: 200px;
height: 200px;
border: 2px solid red;
flex-grow: 0;
padding: 8px;
}
.two {
width: 200px;
height: 200px;
border: 2px solid red;
flex-grow: 0;
padding: 8px;
}
.three {
width: 200px;
height: 200px;
border: 2px solid red;
flex-grow: 0;
padding: 8px;
}
https://codepen.io/anon/pen/GmZWvp
即使在到达列之前将宽度设置为更小 块将列向下推,我怎么能在不影响右侧列的情况下这样做?
我知道我可以定位:绝对主页 div,或在徽标/标题中创建嵌套 div 并给它120px的高度;让它低于标志标题。
但是必须有一种方法可以在列旁边放置一行,而不会将列向下推。 因为徽标标题/主页的 div/row 是一个块元素。
如果您知道如何执行此操作,请告诉我要更改的内容、位置和原因等。 同样,这不是用于生产的,只是为了看看我是否能解决这个古怪的难题。
【问题讨论】:
-
仍然不完全清楚。您能否添加更多详细信息,或发布所需布局的图像。之前和之后的插图可能会有所帮助。
-
我做了@Michael_B,但必须删除图像。我已将其重新添加到主帖中。所需的布局是在主页区域的任意位置连续添加内容,而不会将列向下推。
-
可以修改 HTML 吗?
-
@Michael_B 我现在也添加了问题图片。除了将侧边栏设置为列标题和将页面设置为行之外,任何内容都可以更改。