实际上,这是Pinterest布局.但是,在线发现的解决方案包含在列中,这意味着容器无意中水平生长.这不是 Pinterest布局,并且它不适用于动态加载的内容.
我想要做的是有一堆固定宽度和不对称高度的图像,水平放置,但当满足固定宽度容器的限制时包裹在一个新行中:
flexbox可以做到这一点,还是我不得不求助于像Masonry这样的JS解决方案?
我有一个装满了块的页面display: inline-block.我想做四到两倍大,所以我用float: left或者right把其他块放在一边.
我的问题是,如果我有一个五行元素,我怎么能在它的中间放一个更大的元素?(float自然而然地放在一边).
这是一个示例代码段:
#wrapper{
width: 516px;
}
.block{
display: inline-block;
width: 90px;
height: 50px;
margin: 5px;
background-color: red;
}
.bigger{
height: 110px;
}Run Code Online (Sandbox Code Playgroud)
<div id="wrapper">
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block bigger"></div>
<div class="block"></div>
<div class="block"></div>
</div>Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 Flexbox 实现以下有序布局:
HTML:
<ul class="box-wrapper">
<li class="box boxa">BOX A</li>
<li class="box boxb">BOX B</li>
<li class="box boxc">BOX C</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
CSS:
.box-wrapper{
display:flex;
}
.boxa{
order: 1;
// should be: width: 50%;
// should be: height: 100%;
}
.boxb{
order: 3;
// should be: width: 50%;
// should be: height: 100%;
}
.boxc{
order: 2;
// should be: width: 50%;
// should be: height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
浮动 box-b 和 box-c 似乎不起作用。更改 HTML 布局不是此选项的一种选择。
css ×3
flexbox ×3
css3 ×2
css-grid ×1
grid-layout ×1
html ×1
javascript ×1
layout ×1
pinterest ×1