Html 在<;中对齐高度;部门>;样式内联块
我有这个。 我需要对齐所有行中的高度,如何才能做到这一点Html 在<;中对齐高度;部门>;样式内联块,html,alignment,height,css,Html,Alignment,Height,Css,我有这个。 我需要对齐所有行中的高度,如何才能做到这一点 <div class="test"> <div class="row">one block</div> <div class="row"> three block <br>three block <br>three block <br>three block <br>thr
<div class="test">
<div class="row">one block</div>
<div class="row">
three block
<br>three block
<br>three block
<br>three block
<br>three block
</div>
<div class="row">three block</div>
<div class="row">one block</div>
<div class="row">three block</div>
<div class="row">three block</div>
<div class="row">one block</div>
<div class="row">
three block
<br>dewdfwe
<br>rgegregrethree block
<br>dewdfwe
<br>rgegregre
</div>
<div class="row">three block</div>
</div>
.test{margin: 20px;}
.row{display: inline-block; margin: 2px; text-align: center; width: 200px; border: 1px solid black; border-radius:5px; vertical-align: middle; color: black;}
一个街区
三街区
三街区
三街区
三街区
三街区
三街区
一个街区
三街区
三街区
一个街区
三街区
德夫韦
三号街区
德夫韦
格雷格
三街区
.test{margin:20px;}
.row{显示:内联块;边距:2px;文本对齐:中心;宽度:200px;边框:1px纯黑色;边框半径:5px;垂直对齐:中间;颜色:黑色;}
选项1:静态高度行。
您可以指定每行的高度,然后指定height:100%编码>到该行的单元格。但这不是动态的。如果希望内容垂直对齐,则需要在单元格内放置另一个没有预定义高度的div,然后再次使用vertical align:middle
此方法要求您将每个水平组划分为不同的标记,例如:
div.row
div.cell
div.cell
div.cell
div.row
div.cell
div.cell
div.cell
备选方案:
如果无法分隔行,则可能需要javascript来计算高度。如上所述,每个单元格都是行的100%高度。不过,您不必(一定)拆分每一行,但可能需要重新计算高度
不过,这是非常开放的。使用javascript有一百种方法可以做到这一点
这里有一个解决方案:
它将同一行上所有单元格的高度设置为最高单元格的高度。它不垂直对齐任何内容,但正如我所说的,只需在其中放置另一个div,它具有垂直对齐:middle
。或者查看其他许多垂直对齐选项之一。同样,有一百种方法可以做到这一点。我通过js生成的结果代码。
这里有一些结果的图片
变量line1=[];
变量line2=[]
var tumbler = 0;
var height = $('#t_1').offset().top;
$("div.product__bl").each(function() {
if (tumbler == 0) {
if (height < $(this).offset().top) { tumbler = 1; line2.push(this.id); } else { line1.push(this.id);}
} else { line2.push(this.id); }
//alert(this.id);
});
var maxHeight = 0;
$.each(line1, function(){
var item = $('#'+this).height();
if (item > maxHeight)
maxHeight = item;
});
$.each(line1, function(){
$('#'+this).height(maxHeight+10)
});
maxHeight = 0;
$.each(line2, function(){
var item = $('#'+this).height();
if (item > maxHeight)
maxHeight = item;
});
$.each(line2, function(){
$('#'+this).height(maxHeight+10)
});
var-tumbler=0;
变量高度=$('#t_1').offset().top;
$(“部门产品”)每个(功能(){
如果(不倒翁==0){
if(height<$(this.offset().top){tumbler=1;line2.push(this.id);}else{line1.push(this.id);}
}else{line2.push(this.id);}
//警报(this.id);
});
var maxHeight=0;
$.each(第1行,函数(){
var item=$('#'+this).height();
如果(项目>最大高度)
最大高度=项目;
});
$.each(第1行,函数(){
$('#'+此).高度(最大高度+10)
});
最大高度=0;
$.each(第2行,函数(){
var item=$('#'+this).height();
如果(项目>最大高度)
最大高度=项目;
});
$.each(第2行,函数(){
$('#'+此).高度(最大高度+10)
});
我不明白你的意思。有问题的代码和小提琴中的代码没有任何共同之处。。我需要对齐每行div的高度。我不应该使用最小高度和块的高度,我尽可能地更新了我的答案,尽管问题的范围已经改变。下次尝试提供初始问题的更多信息:)