【问题标题】:Column height responsive to text响应文本的列高
【发布时间】:2017-03-21 13:20:12
【问题描述】:

我想要一行 3 列,根据其中一列内文本的长度/大小,所有 3 列应该具有相同的高度。因此,考虑到最大的列,这 3 列应具有相同的高度并位于同一行。

这是我得到的错误:

http://prntscr.com/d4getm

这是我拥有的代码:

<?php// Define our WP Query Parameters ?>
<?php $the_query = new WP_Query( 'posts_per_page=3' ); ?>

<?php// Start our WP Query ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

      <div class="col-sm-6 col-md-3">

<div class="thumbnail"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(100, 100)); ?></a>
<div class="caption">            
<?php// Display the Post Title with Hyperlink?>
<h3 class="center"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>



<!--// Repeat the process and reset once it hits the limit-->
</div>    
</div>    
</div>

<?php
endwhile;
wp_reset_postdata();
?>

这是 CSS:

div.caption{
    text-align: center;
}
div.thumbnail{
    border: 4px inset black;
    height: 200px;
}
h3.center{
    font-size: 20px;
}

【问题讨论】:

  • 嗨,我也看到了那个帖子,但没有一个解决方案解决了这个问题。有些没有均匀分布列,有些则根本不起作用。

标签: css wordpress twitter-bootstrap


【解决方案1】:

答案在这里:How can I make Bootstrap columns all the same height?

对于这个特殊问题,需要对 html 结构进行一些调整才能使其正常工作。

我已经复制了执行 php 后您的最终 html 的样子。这是一个 js 小提琴:https://jsfiddle.net/qpwgkgfe/39/

更新:这是使用引导类做出响应的 jsfiddle 解决方案:https://jsfiddle.net/qpwgkgfe/44/

基本上,您需要删除一些内容。首先是带有类缩略图的内部 div。您可以通过将类移动到父 div 来获得相同的效果。其次,您需要从 CSS 文件中删除 height: 200px。此设置将覆盖使列匹配的尝试。

我使用了 flex-box 方法,因为它新颖有趣,但经过一些调整,其他解决方案也可以使用。

这是另一个使用 -margin 方法的 js fiddle:https://jsfiddle.net/v92g0ddk/3/

不过,您需要计算出底部边框。

【讨论】:

  • 感谢您的回答,但我想要的是,如果其中一列有更多文本,则其他列的高度应调整到更高的列。我想要同一行中的 3 列,而不是单独的行。你能帮我调整 3 列的高度而不是宽度吗?
  • 我不确定您是否查看过jsfiddle.net/gpwgkgfe/39 链接。尝试更改一列中的文本,然后单击更新并运行。三列将调整它们的大小。你能向我解释一下“同一行”是什么意思吗?就引导程序而言,上述示例被视为在同一行中。\
  • 好的,我想我明白了。您正在查看小型显示器的解决方案。我为 md 大小的屏幕修复了引导程序。我已经用响应式版本更新了答案。
猜你喜欢
  • 2019-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 1970-01-01
  • 2017-02-07
  • 1970-01-01
相关资源
最近更新 更多