CSS Float属性不会将图像元素放在一起,任何人都会看到代码有什么问题?

时间:2011-08-05 18:02:04

标签: css image html css-float stylesheet

这适用于由论文提供支持的Wordpress网站。我想要做的是有一个精选的帖子区域,里面填充了我在精选/精选2类别中添加的任何帖子。

这是PHP

function custom_featured_box() {
    if(is_home()) {
?>
<div id="featuredbox" class="clearfix">
        <?php $my_query = new WP_Query('category_name=featured&showposts=1');
        while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;
        ?>
            <div id="featuredbox-main" style="background: url(<?php the_post_thumbnail('featured') ?>) no-repeat;">
                <a href="<?php the_permalink() ?>"><?php the_title() ?></a>
            </div>
            <?php endwhile; ?>
        <?php $my_query = new WP_Query('category_name=featured2&showposts=3');
        while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; 
        ?>
            <div id="featuredbox-secondary">
                <div class="secondary-item" style="width: 205px; background: url(<?php the_post_thumbnail() ?>) no-repeat;">
                    <a href="<?php the_permalink() ?>"><?php the_title() ?></a>
                </div>
            </div>
        <?php endwhile; ?>
    </div>
<?php
} }

“新WP_Query”功能只是调用类别“精选”和“精选2”(&lt; - 这是针对次要精选帖子)并获取第一篇帖子(针对“精选”类别)和前3位(对于“featured2”类别)并将它们放在精选帖子部分。我遇到的唯一问题是#featured-secondary不会将“featured2”帖子放在彼此旁边。此外,缩略图还没有显示,但我还没有想过想弄清楚它。

这是CSS:

.custom #feature_box { padding:0em; }

.custom #featuredbox { padding: 8px 0 10px 0;}
.custom #featuredbox-main {overflow: hidden; width: 650px; height: 225px; border: solid      
1px #ccc; margin: 0 0 10px 0; position: relative;}
.custom #featuredbox-main a:hover {text-decoration: underline;}
    .custom #featuredbox-main a {z-index: 1; position: absolute; top: 121px; min-   
height: 35px; left: 0; font-size: 20px; font-weight: bold; color: #fff; padding: 15px 
10px; width: 100%; background: url(http://location-of-the-background-here);}

.custom #featuredbox-secondary {height: 162px; overflow: hidden; width: 650px;}
    .custom .secondary-item {margin-right: 10px; position: relative; border: solid 1px 
#ccc; height: 160px; float: left; overflow: hidden;}
    .custom .secondary-item a:hover {text-decoration: underline;}
    .custom .secondary-item a {z-index: 1; position: absolute; top: 52px; left: 0; 
font-size: 12px; font-weight: bold; color: #fff; padding: 8px 10px; width: 185px;    
background: url(http://location-of-the-background-here);}

我不明白为什么CSS没有让#featuredbox-secondary帖子彼此相邻。

非常感谢任何帮助。

P.S。这是一个截图,显示当前代码的样子,希望它可以帮助人们了解我的目标。 http://img43.imageshack.us/img43/3011/csshelp.jpg

1 个答案:

答案 0 :(得分:0)

如果我理解正确的话,那么你希望每个具有“二级项目”的div在div中与ID“featuredbox-secondary”一起漂浮在彼此旁边?如果是这样,您需要将float声明应用于“secondary-item”类。