html - 如何将这些 div 粘在一起?

标签 html css wordpress

我想坚持 3 个 div,但我做不到。我不知道怎么了。

这是一个screenshot .

HTML

<div id="container">
    <?php if(have_posts()) : ?>
        <?php while(have_posts()) : the_post(); ?>
            <div class="post" id="post-<?php the_ID(); ?>">
                <h2>
                    <a href="<?php the_permalink(); ?>"title="<?php the_title(); ?>"><?php the_title(); ?></a>
                </h2>
            </div>
            <div class="entry"><?php the_content(); ?></div>

            <p class="postmetadata">
                <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
                <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?>
                <?php edit_post_link('Edit', ' &#124; ', ''); ?>
            </p>
        <?php endwhile; ?>

        <div class="navigation"><?php posts_nav_link(); ?></div>

    <?php else : ?>
        <div class="post"><h2><?php _e('Not Found'); ?></h2></div>
    <?php endif; ?>
</div>

CSS

.post{
  padding: 10px 5px 0 5px;
  background-image: url(images/toppost.png);
  background-repeat:no-repeat !important;
}


.post h2{
  font-family: Arial, Sans-serif;
  font-size: 18px;
  margin: 0px 0 0px 0px;
}

.entry{
  background-image:url(images/ContentBG.png);
  margin: 0 0 0 0;
  padding:0 5px !important;
  background-position: bottom;
}

.postmetadata {
  clear: both;
  background-image: url(images/post-footer.png);
  background-repeat: no-repeat;
  height:118px;
  padding:0 5px !important;
}

最佳答案

您可能需要删除这些 DIV 中元素的边距。例如。如果第一个 DIV 中的最后一个元素有底部边距,它将“泄漏”并导致间隙。第二个 DIV 中的第一个元素也是如此。

尝试创建这个文档:

<html>
  <head>
    <style>
    /*p, h2 { margin: 0; }*/
    </style>
  </head>

  <body>
    <div style="background-color: #eee;"><p>Lorem ipsum</p></div>
    <div style="background-color: #ddd;"><p>Dolor sit amet</p></div>
  </body>
</html>

并比较取消注释样式时发生的情况。请注意,这里有背景色,因此您可以看到 DIV。

关于html - 如何将这些 div 粘在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7301196/

相关文章:

html - 使 iframe 和页脚发挥良好

jQuery:添加无限输入和处理表单数据

css - 页面末尾错误 (XML SVG) & CSS 不工作

javascript - 为什么我的两个 div 总是紧挨着?

PHP 读取文件返回数据

javascript - 如何修复追加功能后表格行未被单击的问题?

javascript - 在不同的 .js 文件之间传递变量;一个在 iframe 中

html - 对齐 <li> 元素但 overflow hidden

php - 如何从 MySQL 时间戳数据类型的日期中减去一天?

php - WordPress paginate_links - 如何使用它?