我们div
在我们的网站上有一个并且想要垂直对齐其中的文本(不是垂直对齐或居中对齐)。
这是一个基本示例(使用 Bootstrap 3+,顺便说一句):
<div class="row">
<div class="col-xs-12 col-sm-4 v-justify">
this is our text that we need verticlaly justified. lorem ipsum dolor amet, etc...
</div>
<div class="col-xs-12 col-sm-4 portCell">
This is a div with a responsive image in it so we don't know the height.
For arguments sake we'll say 300px
</div>
<div class="col-xs-12 col-sm-4 portCell">
This is a another div with a responsive image in it so we don't know the height.
For arguments sake we'll say 300px
</div>
</div>
我们怎样才能让第一个 DIV 中的文本垂直对齐。仅 CSS 解决方案的加分项,具有媒体查询友好的样式,可提供完整的设备支持。
答案基于 Andrew Rockwell 的解决方案
这按类循环(v-justify),因此我们可以将其应用于我们网站上的多个区域。
$('.v-justify').each(function(){
var justify = $(this);
var maxHeight = justify.parent().next('.portCell').height();
var fontSize = 1.5;
while ( maxHeight > justify.height() ) {
justify.css('font-size', (fontSize+=1.7) + 'px');
}
});