【问题标题】:absolute positioning not aligning properly绝对定位未正确对齐
【发布时间】:2015-07-16 07:55:57
【问题描述】:

以下代码...

<article id="post-<?php the_ID(); ?>" style="background-image:url('<?php echo $thumbnail_url ?>')" <?php post_class('container-fluid'); ?> >

<div class="container-fluid text-cell">
   <div class="col-md-12 textr">
     <h2><a href="<?php the_permalink(); ?>" rel="bookmark"><?php  the_title(); ?></a></h2>
     <?php the_category(', '); ?>
   </div>   
</div>

</article><!-- /#post -->

... 为我的 Wordpress 主题创建帖子。它用标题、类别和背景图像组成一行(100% 宽度)。每个帖子都堆叠在一起。

我希望标题和类别留在文章的底部(我在 div 上放置了一个 'textr' 类,以便将它们组合在一起。

然而,这个 div 现在位于它应该在的文章的顶部,而不是内部和底部

css

article {
  background-repeat: no-repeat;
  background-size: cover;
  border-top: 1px solid #000;
  background-position: left center;
  height: 400px;
  margin: 0;
  padding: 0;
}

.text-cell {
  position: relative;
  margin: 0;
  padding: 0;
}

.textr{
  position: absolute;
  left: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
}

【问题讨论】:

    标签: html css wordpress css-position absolute


    【解决方案1】:

    尝试将 position: relative;.text-cell 移动到 article

    你也可以将.text-cell修改成这样:

    .text-cell {
        position:absolute;
        width:100%;
        height:100%;
        margin:0;
        padding:0;
    }
    

    【讨论】:

    • 我设法修复了它!尽管您的方法不起作用(我无法将文章定位为绝对原因,然后它就不会堆叠)并且对 text-cell 的更改并不能解决问题。但是添加位置:相对于文章确实
    猜你喜欢
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多