【问题标题】:Equal heights of elements and align to bottom元素的高度相等并与底部对齐
【发布时间】:2018-10-19 20:31:48
【问题描述】:

如何设置每个内容的高度相等,并在内容后平均内联span

CSS

.box {
  width: 100%;
  position: relative;
  margin: 0 auto;
}

.box-image {
    position: relative;
    height: auto;
    margin: 0 auto;
    overflow: hidden;
}
.box, .box-image, .box-text {
    transition: opacity 0.3s, background-color 0.3s, -webkit-transform 0.3s;
    transition: opacity 0.3s, transform 0.3s, background-color 0.3s;
    transition: opacity 0.3s, transform 0.3s, background-color 0.3s, -webkit-transform 0.3s;
}


.text-center {
    text-align: center;
}
.box-text {
    padding-top: .7em;
    padding-bottom: 1.4em;
    position: relative;
    width: 100%;
    font-size: .9em;
}

.box-text  p {
        margin-bottom: 1.9em;
        font-size:14px;
}

.box-text h3 {
    font-size: 14px;
    color: #272627;
    text-align: center;
    font-family: Poppins;
    font-weight: 700;
    font-style: normal;
}

.totalviewpost, .catname a, .timeago {
    font-size: 10px !important;
    color: #272627;
    text-align: left;
    font-family: Poppins;
    font-weight: 400;
    font-style: normal;
     text-shadow: none;
}

.totalviewpost:before {
    content: '\f06e';
    display: inline-block;
    font-family: FontAwesome;
    font-size: 12px;
    margin-right: 10px;
}

.timeago:before {
    content: '\f017';
    display: inline-block;
    font-family: FontAwesome;
    font-size: 12px;
    margin-right: 10px;
}

.catname:before {
    content: '\f03a';
    display: inline-block;
    font-family: FontAwesome;
    font-size: 12px;
    margin-right: 10px;
    color: #272627 !important; 
}

HTML

    <div class="box has-hover has-hover box-text-bottom" >
                     <div class="box-image" >
                        <div class="" >
                           <a onClick="<?php echo get_the_ID();?>" data-postid="<?php echo get_the_ID();?>" href="<?php the_permalink(); ?>">
                           <img src="<?php echo the_post_thumbnail_url() ?>" width="277" height="277"> 
                           </a>                                      
                        </div>
                     </div>
                     <!-- box-image -->
                     <div class="box-text" >
                        <div class="box-text-inner">
                           <h3 style="text-align: left;"><a onClick="<?php echo get_the_ID();?>" data-postid="<?php echo get_the_ID();?>" href="<?php the_permalink(); ?>"><?php the_title();?></a></h3>
                           <p class="content" style="text-align: left;"><?php 
                              $trimmed = wp_filter_nohtml_kses( wp_trim_words( get_the_content(), 20, '....') );

                              echo $trimmed;        
                               ?></p>
                               <div>
                              <span class="totalviewpost"><?php echo getPostViews(get_the_ID()); ?>  &nbsp;| &nbsp; </span>
                              <span class="timeago"><?php echo get_the_date( 'Y-m-d' ); ?> &nbsp; | &nbsp;</span> 
                              <span class="catname"><?php $category = get_the_category(); ?>
<a  href="<?php echo get_category_link($category[0]->cat_ID); ?> ">
<?php echo $category[0]->cat_name; ?> </a></span></div>
                        </div>
                        <!-- box-text-inner -->
                     </div>
                     <!-- box-text -->
                  </div>

问题截图

【问题讨论】:

  • 我也应该粘贴 CSS 吗?
  • @Paulie_D CSS 和完整代码更新请查看
  • @Paulie_D 如何设置相同的跨度?
  • 没关系,我已经添加了一个答案来解释如何管理它。
  • 设置该 div 绝对值并为父 div 提供填充底部,这可能是您的问题的解决方案

标签: html css height


【解决方案1】:

没有没有 CSS 方法来对齐元素/均衡高度不共享父元素

可以做什么,在这种情况下,将最后一个 div 推到每列的底部。

Flexbox 可以做到这一点。您必须根据您的情况调整以下示例中的代码,但这是原则。

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

 ::before,
 ::after {
  box-sizing: inherit;
}

.wrap {
  display: flex;
  width: 90%;
  margin: auto;
}

.box {
  flex: 1 0 33%;
  border: 1px solid grey;
  margin: 1em;
  display: flex;
  flex-direction: column;
  padding: .5em;
}

.img-wrap {
  text-align: center;
}

img {
  max-width: 100%;
}

footer {
  margin-top: auto;
  background: pink;
}
<div class="wrap">
  <div class="box">
    <div class="img-wrap"> <img src="http://www.fillmurray.com/300/200" alt=""></div>
    <h3>Lorem, ipsum dolor.</h3>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sed ratione accusantium iure laudantium vero doloribus. Lorem ipsum dolor sit amet consectetur adipisicing elit. Ea, cumque.</p>
    <footer>My footer</footer>
  </div>
  <div class="box">
    <div class="img-wrap"> <img src="http://www.fillmurray.com/300/200" alt=""></div>
    <h3>Lorem, ipsum dolor.</h3>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sed ratione accusantium iure laudantium vero doloribus.</p>
    <footer>My footer</footer>
  </div>
  <div class="box">
    <div class="img-wrap"> <img src="http://www.fillmurray.com/300/200" alt=""></div>
    <h3>Lorem, ipsum dolor.</h3>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
    <footer>My footer</footer>
  </div>
</div>

【讨论】:

    猜你喜欢
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 2016-04-20
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多