【问题标题】:100% height on absolute positioned div绝对定位 div 上的 100% 高度
【发布时间】:2015-07-22 08:07:20
【问题描述】:

我的 WP 网站中有由帖子创建的响应式“单元格”。

HTML

<article>

    <div id="post-<?php the_ID(); ?>" <?php post_class( 'row'); ?> >

        <div class="col-md-12">
            <div class="text-cell">
                <h1><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
                <h3><?php the_category(' '); ?></h3>
            </div>
        </div>

    </div>
    <!-- /#post -->

</article>

CSS

article {
    position: relative;
    margin: 0;
    padding: 18% 0;
}

.text-cell {
    position: absolute;
    height: 100%;
    width: 30%;
    top: 0;
    left: 0;
    background-color: #fff;
}

如果可能,我不希望“文章”设置高度(我使用填充为“文章”创建动态高度)

我希望“文本单元格”是文章的全高和宽度的 30%。在它移动之前,它将是全宽和 30% 的高度。 100% 的高度似乎不起作用。

视觉前。

【问题讨论】:

  • Set height 100% on absolute div 的可能重复项
  • 您当前的代码不起作用吗? jsfiddle.net/fzwqn3uh/2
  • 我认为应该,但我的“背景颜色”没有显示。但我希望它像你的小提琴表演一样工作
  • 那么你的框架导致了这个问题,元素上可能有更多的css

标签: javascript jquery html css


【解决方案1】:

尝试将bottom 添加到您的定位方案中:

.text-cell {
  position: absolute;
  /* height: 100%; <-- remove this */
  width: 30%;
  bottom: 0; /* <-- add this */
  top:0;
  left:0;
  background-color: #fff;
}

如果这不起作用,则说明.col-md-12 DIV 或article DIV 的高度存在问题。

【讨论】:

  • 我添加了底部,但它不起作用,'.col-md-12' 是一个引导函数,只制作列(不处理高度),这是唯一的样式文章。 “文本单元”内的文本垂直居中,但背景根本不显示(指示高度问题)
猜你喜欢
  • 2012-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-11
  • 1970-01-01
  • 2012-12-22
  • 1970-01-01
  • 2011-05-06
相关资源
最近更新 更多