Sci*_*nce 105 html css flexbox
CodePen:http://codepen.io/anon/pen/RPNpaP .我希望红色框在并排视图中只有25 em宽 - 我试图通过设置内部的CSS来实现这一点
@media all and (min-width: 811px) {...}
Run Code Online (Sandbox Code Playgroud)
至
.flexbox .red {
width: 25em;
}
Run Code Online (Sandbox Code Playgroud)
但当我这样做时,会发生这种情况:
http://i.imgur.com/niFBrwt.png
知道我做错了什么吗?非常感谢.
Sti*_*ers 238
你应该使用flex或flex-basis属性而不是width.阅读有关MDN的更多信息.
.flexbox .red {
flex: 0 0 25em;
}
Run Code Online (Sandbox Code Playgroud)
该flexCSS属性是一个速记属性指定柔性项目,以改变其尺寸以填充可用空间的能力.它包含:
flex-grow: 0; /* do not grow - initial value: 0 */
flex-shrink: 0; /* do not shrink - initial value: 1 */
flex-basis: 25em; /* width/height - initial value: auto */
Run Code Online (Sandbox Code Playgroud)
一个简单的演示展示了如何将第一列设置为50px固定宽度.
.flexbox {
display: flex;
}
.red {
background: red;
flex: 0 0 50px;
}
.green {
background: green;
flex: 1;
}
.blue {
background: blue;
flex: 1;
}Run Code Online (Sandbox Code Playgroud)
<div class="flexbox">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>Run Code Online (Sandbox Code Playgroud)
根据您的代码查看更新的codepen.
实际上,如果你确实想使用 width CSS 属性,另一个解决方法是应用这个:
.flexbox .red {
width: 100%;
max-width: 25em;
}
Run Code Online (Sandbox Code Playgroud)
如果有人想要一个带有百分比 (%) 的响应式 flexbox,媒体查询会更容易。
flex-basis: 25%;
Run Code Online (Sandbox Code Playgroud)
这在测试时会顺畅很多。
// VARIABLES
$screen-xs: 480px;
$screen-sm: 768px;
$screen-md: 992px;
$screen-lg: 1200px;
$screen-xl: 1400px;
$screen-xxl: 1600px;
// QUERIES
@media screen (max-width: $screen-lg) {
flex-basis: 25%;
}
@media screen (max-width: $screen-md) {
flex-basis: 33.33%;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
101798 次 |
| 最近记录: |