[英]Height 100% on justified inline-block div's
I have a page with a dynamic number of boxes that I would like to distribute over several columns and lines. 我有一个页面,其中包含动态数量的框,我希望将它们分布在几行和几行中。
I have the following wishes: 我有以下愿望:
Ideally I'dd like the page to be responsive, so the number of columns should adjust to the browser width. 理想情况下,我希望页面具有响应性,因此列数应根据浏览器宽度进行调整。 But after reading and watching a lot of examples I don't see how this is possible in combination with the justifying, as that always needs a row div. 但是在阅读并观看了很多示例之后,我看不到将这种方法与合理性结合起来是怎么可能的,因为这总是需要一个行div。
So I'm going for a fixed number of columns. 所以我要固定数量的列。 With all kinds of examples I came to this solution, but there is still one challenge: getting each div to have the same height: 通过各种示例,我来到了此解决方案,但仍然存在一个挑战:使每个div具有相同的高度:
http://jsfiddle.net/johannesklapwijk/BQJ6A/ http://jsfiddle.net/johannesklapwijk/BQJ6A/
HTML: HTML:
<div class='row'>
<div class='cell'>a<br/>b</div>
<div class='cell'>a<br/>b<br/>c</div>
<div class='cell'>a<br/>b</div>
<span class='stretch'/>
</div>
CSS: CSS:
.row {
text-align: justify;
border: 1px solid red;
padding: 0;
}
.cell {
display: inline-block;
width:30%;
height: 100%; /* does not get the height of the parent div */
border: 1px solid black;
background-color: green;
}
.stretch {
width: 100%;
display: inline-block;
font-size: 0;
line-height: 0
}
I have two questions I guess: 我猜有两个问题:
Thanks! 谢谢!
So like this? 像这样吗 (Change the con width to 100% if you want it the size of the browser) (如果需要浏览器大小,请将con宽度更改为100%)
HTML: HTML:
<div class="con">
<div class="col">asd</div>
<div class="col">asdasdasd
<br />asdas
<br />asdasd
<br />asdasd
<br />asdasd</div>
<div class="col">asd</div>
</div>
CSS 的CSS
.con {
height: 100%;
width: 400px;
display: table;
table-layout: fixed;
}
.col {
display: table-cell;
border: #000000 solid 1px;
}
And for if you want it the size of the browser change width
on .con
如果您愿意,浏览器的大小会更改.con
width
width: 100%;
and if you want the spacing like you have on yours add border-spacing
to .con
如果您想要像您一样border-spacing
,请将border-spacing
添加到.con
border-spacing: 10px;
I've been trying to find something that meets my needs and I'm afraid CSS only is not enough. 我一直在尝试找到满足我需求的东西,但恐怕仅CSS还是不够的。
I guess the jQuery freewall plug-in might give me what I need, even though it might be a bit heavy for my wishes. 我猜想jQuery freewall插件可能会满足我的需求,尽管它可能有点沉重。
http://vnjs.net/www/project/freewall/ http://vnjs.net/www/project/freewall/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.