0

ブログコンテナに、ページ全体とは別の背景を設定したいと思います。ただし、bg.pngではなくwood.pngを背景として使用しています。私は以下を使用しています:

CSS

body {
 background: url('img/bg.png') repeat;
}
.above {
 background: url('img/wood.png') repeat;
 width: 100%;
}
#blog-header {
 background: url('img/wood.png') repeat; 
 height: 160px;
 width: 100%;
 text-align: center;
}
#blog-container {
 background: url('img/bg.png') repeat;
 margin: 0 auto;
 width: 960px;
}
#blog {
 float: left;
 margin-top: 80px;
 position: relative;
 width: 620px;
}

HTML / PHP

<body>
<div class="above">
 <div id="blog-header">
  <div class="logo">
   <a href="<?php bloginfo('url'); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/logo.png" alt="Urban Palate logo" id="logo" /></a>
   </div><!-- end logo -->
   <nav>
    <ul>
     <li><a href="/?page_id=7"><img src="<?php echo get_template_directory_uri(); ?>/img/about.png" alt="Urban Palate intro" /></a></li>
     <li><a href="/?page_id=12"><img src="<?php echo get_template_directory_uri(); ?>/img/portfolio.png" alt="Urban Palate portfolio" /></a></li>
     <li><a href="/?page_id=15"><img src="<?php echo get_template_directory_uri(); ?>/img/blog.png" alt="Urban Palate blog" /></a></li>
     <li><a href="/?page_id=10"><img src="<?php echo get_template_directory_uri(); ?>/img/contact.png" alt="Urban Palate contact" /></a></li>
    </ul>
   </nav>
   </div><!-- end blog-header -->
   <div id="blog-container">
    <div id="blog">
     <div id="post">
       //content
     </div><!-- end post -->
    </div><!-- end blog -->
   </div><!-- end blog-container -->

問題を引き起こしている可能性のあるアイデアはありますか?

ETA:JSFiddle

4

2 に答える 2

1

要素にフローティング要素が含まれている場合、ラッピング要素には、背景を追加するために必要な高さを取得するためにaoverflow:autoまたはaが必要です。clear:both;

あなたの場合、以下に示すように、overflow:autoまたはclear:bothを追加するか#blog-container、別のクラスとして追加することができます。

これは、cssにclearfix宣言を追加するために使用できるいくつかの優れた行です。フローティング要素を含む任意の要素にそのクラスを追加できます。

/*
 * Clearfix: contain floats
 *
 * For modern browsers
 * 1. The space content is one way to avoid an Opera bug when the
 *    `contenteditable` attribute is included anywhere else in the document.
 *    Otherwise it causes space to appear at the top and bottom of elements
 *    that receive the `clearfix` class.
 * 2. The use of `table` rather than `block` is only necessary if using
 *    `:before` to contain the top-margins of child elements.
 */

.clearfix:before,
.clearfix:after {
    content: " "; /* 1 */
    display: table; /* 2 */
}

.clearfix:after {
    clear: both;
}

/*
 * For IE 6/7 only
 * Include this rule to trigger hasLayout and contain floats.
 */

.clearfix {
    *zoom: 1;
}

クリアフィックスは、Html5Boilerplateから取得されます

そして、ここに、clearfixの違いについて話している特別な質問があります:clearfixのどの方法が最適ですか(回答2を確認してください)

于 2012-09-30T18:34:03.697 に答える
0

体にパディングを設定する必要がある場合があります(またはdiv幅を100%ではなく95%に設定します)。divが画面の全幅を占めるようです。

于 2012-09-30T18:41:15.773 に答える