【发布时间】:2015-09-30 16:59:14
【问题描述】:
所以我有这个带有以下 CSS 的 HTML 代码。
HTML
<div class="secondpostholder">
<div class="rightsecond">
<h1>
<a href="<?php the_permalink();?>" alt="<?php the_title();?>" title="<?php the_title();?>">
<?php the_title();?>
</a>
</h1>
<div class="firstmetaholder">
<p class="secondentrymeta">
by
<span class="secondauthormeta">
<?php the_author();?>
</span>
• <?php the_date(); ?>
</p>
<p class="secondentryexcerpt">
<?php
$content = get_the_content();
echo wp_trim_words( $content , '30' ); ?>
</p>
<div class="secondreadmoreholder">
<a class="secondreadmorea" href="<?php the_permalink();?>" alt="<?php the_title();?>" title="<?php the_title();?>">
Read More
</a>
</div>
</div>
</div>
<?php $background = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'TypeOne' ); ?>
<div class="leftsecond" style="background-image: url('<?php echo $background[0]; ?>');">
<a class="leftseconda" href="<?php the_permalink();?>" alt="<?php the_title();?>" title="<?php the_title();?>">
</a>
</div>
</div>
CSS
secondentry {
display:inline-block;
width:100%;
}
.secondentryholder {
width:100%;
max-width:1120px;
margin:0 auto;
position:relative;
height:100%;
}
.secondpostholder {
margin-bottom:60px;
}
.rightsecond{
width: 420px;
right:0;
position: absolute;
margin-left:30px;
}
.secondpostholder {
clear:both;
}
.leftsecond{
background: #222;
float:left;
width:calc(100% - 450px);
min-height:400px;
background-repeat:no-repeat;
display:block;
position:relative;
background-position:center center;
}
您可以访问我正在努力的the website,以清楚了解正在发生的事情。
打开网站后,将浏览器窗口的大小调整为 600 像素,然后查看第二个帖子 (“我们在一个绝望的地方找到了爱情”) 到第六个帖子 (“无可争议真相:如果您不支付信用卡账单会怎样?") 看看会发生什么。
我的问题是,有没有办法让 "leftsecond" DIV 位于 "rightsecond" 的顶部?
我知道这可以通过修改 HTML 结构轻松完成但是请注意两个 div 的原始 CSS 样式是浮动的。
我在这里想要实现的与媒体查询有关,当屏幕很大时,两个 div 会相互浮动。这段代码没有问题。问题出在屏幕很小并且我想删除 FLOATS 时,“leftsecond div”将位于顶部,而“rightsecond div”位于底部。
两个divs 的高度不同。只有“leftsecond”div 具有固定高度。右边第二个div 有一个流动的高度,它会根据它的内容而变化。
【问题讨论】:
-
嗨@Harry,感谢您的帮助。我忘了提到底部有几个“secondpostholder”也包含相同的#blue 和#left div。问题是它相互重叠。我认为应该在“secondpostholder”中添加一些东西来识别其子div的高度。我已经更新了小提琴。请以 ANSWER 形式回复,以便我奖励您的努力。
-
很抱歉打扰,但我添加到答案中的最新方法有帮助吗?
-
嗨,Harry,很抱歉没有回复您。我还没有测试代码,因为我现在正忙于我的日常工作。无论如何,我计划在周末在我的网站上工作,所以到那时我将对其进行测试。我很抱歉。
-
我只是查看了您的代码并运行了代码 sn-p 并且它可以工作。所以我想这也适用于我的 wordpress 网站..
标签: html css media-queries