[英]Floating fieldset with same height
I've this code: 我有这个代码:
<div id="container">
<fieldset class="box">
<legend>Title</legend>
CONTENT
</fieldset>
<fieldset class="box">
[etc...]
</fieldset>
</div>
I would like to have these fieldsets with the same height and floating. 我想让这些字段集具有相同的高度和浮动。
So I've set the container with display:table
and each fieldset with display:table-cell
but, if I use float:left
to floating each box (fieldset), display:table-cell
doesn't work anymore. 所以我用
display:table
和每个fieldset设置了display:table-cell
但是,如果我使用float:left
来浮动每个box(fieldset), display:table-cell
不再工作了。
This should be the result: 这应该是结果:
Any suggestion? 有什么建议吗?
Using simple jQuery code you can achieve the equal column height 使用简单的jQuery代码,您可以实现相等的列高
HTML HTML
<div id="container">
<fieldset class="box">
<legend>Title</legend>CONTENT
<br/>test</fieldset>
<fieldset class="box">
<legend>Title</legend>CONTENT</fieldset>
<fieldset class="box">
<legend>Title</legend>CONTENT</fieldset>
</div>
CSS CSS
.box {
float:left;
width:25%;
}
jQuery jQuery的
$(function () {
var H = 0;
$("div").each(function (i) {
var h = $(".box").eq(i).height();
if (h > H) H = h;
});
$(".box").height(H);
});
Ok I will create an answer. 好的,我会创建一个答案。 So put it simply,
display: table-cell
cannot be used with fieldset
. 简单地说,
display: table-cell
不能与fieldset
一起使用。 Find out more in this question 在这个问题中了解更多信息
You could just use div
and change the look a little bit. 你可以使用
div
并稍微改变一下。 Or just use them as containers for each. 或者只是将它们用作每个容器。
But I would recommend using display: inline-block
for this. 但我建议使用
display: inline-block
。
<div id="container">
<fieldset class="box">
<legend>Title</legend>CONTENT</fieldset>
<fieldset class="box">
<legend>Title</legend>CONTENT</fieldset>
<fieldset class="box">
<legend>Title</legend>CONTENT</fieldset>
</div>
.box {
width: 200px;
height: 200px;
display: inline-block;
}
And this is how you could create containers around them to be able to use display: table;
这就是你可以在它们周围创建容器以便能够使用
display: table;
etc. 等等
<div id="container">
<div class="innercon">
<fieldset class="box">
<legend>Title</legend>CONTENT</fieldset>
</div>
<div class="innercon">
<fieldset class="box">
<legend>Title</legend>CONTENT</fieldset>
</div>
<div class="innercon">
<fieldset class="box">
<legend>Title</legend>CONTENT</fieldset>
</div>
</div>
#container {
display: table;
}
.innercon {
display: table-cell;
}
.box {
width: 200px;
height: 200px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.