2016-08-22 46 views
1

好的,也許我略微失去了想法,但我試圖重新創建一個主頁,將2個背景圖像合併到我的CSS中。我試圖使用一個作爲頂部圖像,一個作爲底部圖像,中間是一張有鏈接和圖像的表格。然而,出於某種原因,我很難將它們拉在一起,使它看起來像一個平滑的圖像。爲什麼我的CSS不合作?

例如,我的容器類(如下所示)只在topBox類周圍放置邊框,而不是整個容器div。我希望所有3個div都有一個邊框(來自容器類),使其看起來像是一個圖像。這是我的HTML和CSS。

我在做什麼錯?在此先感謝您的幫助!

 #Container { 
 
     float:left; 
 
     width: inherit; 
 
     height: 400px; 
 
     margin-left: auto; 
 
     margin-right: auto; 
 
     border:1px solid #000000; 
 
     } 
 

 

 
     .boxTop { 
 
     position: relative; 
 
     left: 100; 
 
     top: 100; 
 
     width: inherit; 
 
     height: 95px; 
 
     background-image:  url(http://ejgh.org/templates/ejgh/images/HL_logo.jpg); 
 
     background-repeat: no-repeat; 
 
     /*place background image css code here and remove line above*/ 
 
      background-position: left 0px top 0px; 
 
    background-size: 300px; 
 

 
     } 
 

 
     .box { 
 
     position: relative; 
 
     left: 100; 
 
     top: 100; 
 
     width: 350px; 
 
     height: 550px; 
 
     border:0px solid #000000; 
 
} 
 

 
     .boxBtm { 
 
     position: relative; 
 
     left: 100; 
 
     top: 100; 
 
     width: inherit; 
 
     height: 95px; 
 
     background-image: url(http://ejgh.org/templates/ejgh/images/healthyLifestyles_bottom.gif); 
 
     /*place background image css code here and remove line above*/ 
 
     background-repeat: no-repeat; 
 
      background-position: left 0px bottom 0px; 
 
    background-size: 300px; 
 
     }
<div id="Container"> 
 
    <div class="boxTop"></div> 
 
    <div class="box"><table width="300px"> 
 
<tbody> 
 
<tr> 
 
<td> 
 
<table cellspacing="0" cellpadding="6"> 
 
<tbody> 
 
<tr> 
 
<td valign="top"><a href="http://ejgh.org/your-health/healthy-lifestyles/become-a-member-sp-1672965733"><img style="border-width: 0px;" src="http://ejgh.org/images/stories/template/healthylifestyles/apple.jpg" alt="Image of Apple and Weights for homepage" width="86" height="86" /></a></td> 
 
<td valign="top"> 
 
<h3><a href="/your-health/healthy-lifestyles/become-a-member-sp-1672965733">Become a Member</a></h3> 
 
<p>Join Healthy Lifestyles and enjoy the benefits of membership.</p> 
 
</td> 
 
</tr> 
 
<tr> 
 
<td valign="top"><a href="/component/wrapper/?Itemid=203"><img style="border-width: 0px;" src="http://ejgh.org/images/stories/template/healthylifestyles/elderlycouple.jpg" alt="Image of elderly couple at hospital in New Orleans Louisiana" width="86" height="83" /></a></td> 
 
<td valign="top"> 
 
<h3><a href="/your-health/healthy-lifestyles/classes-support">Classes &amp; Support</a></h3> 
 
<p>Learn more about the classes, support groups, and health screenings we offer.</p> 
 
</td> 
 
</tr> 
 
<tr> 
 
<td valign="top"><a href="/component/hwdvideoshare/?task=viewcategory&amp;Itemid=166&amp;cat_id=5"><img style="border-width: 0px;" src="http://ejgh.org/images/stories/template/healthylifestyles/tvspot.jpg" alt="Image of Liz Delsa Healthy Lifestyles Host" width="86" height="70" /></a></td> 
 
<td valign="top"> 
 
<h3><a href="/your-health/healthy-lifestyles/healthy-lifestyles-tv">Watch the TV Segment</a></h3> 
 
<p>Watch Healthy Lifestyles TV segments as seen on WWL-TV.</p> 
 
</td> 
 
</tr> 
 
<tr> 
 
<td valign="top"><a href="/your-health/healthy-lifestyles/healthy-lifestyles-magazine"><img src="http://ejgh.org/images/stories/yourhealthimages/healthylifestyles/MagazineCovers/summer2016.jpg" alt="Summer 2016 Healthy Lifestyles Cover" width="86" height="100" /></a></td> 
 
<td valign="top"> 
 
<h3><a href="/your-health/healthy-lifestyles/healthy-lifestyles-magazine">Read the Magazine</a></h3> 
 
<p>Read the latest Healthy Lifestyles Magazine as included in the Times-Picayune newspaper.</p> 
 
</td> 
 
</tr> 
 
</tbody> 
 
</table> 
 
</td> 
 
</tr> 
 
</tbody> 
 
      </table></div> 
 
    <div class="boxBtm"></div> 
 
</div>

回答

2

很簡單的答案,只是刪除ID的#container的HIGHT,它會工作。我希望這是你尋找的東西;)

+0

是的,它是 - 謝謝你。只要我發佈這個問題,我意識到這就是它。我忘了刪除它。感謝您的答覆! – kjkentner

2

你已經在你的容器上設置了一個特定的height,所以你的border只會是那個高度。如果將高度設置爲750像素,則它將起作用。

#Container { 
 
    float: left; 
 
    width: inherit; 
 
    height: 750px; 
 
    margin-left: auto; 
 
    margin-right: auto; 
 
    border: 1px solid #000000; 
 
} 
 
.boxTop { 
 
    position: relative; 
 
    left: 100; 
 
    top: 100; 
 
    width: inherit; 
 
    height: 95px; 
 
    background-image: url(http://ejgh.org/templates/ejgh/images/HL_logo.jpg); 
 
    background-repeat: no-repeat; 
 
    /*place background image css code here and remove line above*/ 
 
    background-position: left 0px top 0px; 
 
    background-size: 300px; 
 
} 
 
.box { 
 
    position: relative; 
 
    left: 100; 
 
    top: 100; 
 
    width: 350px; 
 
    height: 550px; 
 
    border: 0px solid #000000; 
 
} 
 
.boxBtm { 
 
    position: relative; 
 
    left: 100; 
 
    top: 100; 
 
    width: inherit; 
 
    height: 95px; 
 
    background-image: url(http://ejgh.org/templates/ejgh/images/healthyLifestyles_bottom.gif); 
 
    /*place background image css code here and remove line above*/ 
 
    background-repeat: no-repeat; 
 
    background-position: left 0px bottom 0px; 
 
    background-size: 300px; 
 
}
<div id="Container"> 
 
    <div class="boxTop"></div> 
 
    <div class="box"> 
 
    <table width="300px"> 
 
     <tbody> 
 
     <tr> 
 
      <td> 
 
      <table cellspacing="0" cellpadding="6"> 
 
       <tbody> 
 
       <tr> 
 
        <td valign="top"> 
 
        <a href="http://ejgh.org/your-health/healthy-lifestyles/become-a-member-sp-1672965733"> 
 
         <img style="border-width: 0px;" src="http://ejgh.org/images/stories/template/healthylifestyles/apple.jpg" alt="Image of Apple and Weights for homepage" width="86" height="86" /> 
 
        </a> 
 
        </td> 
 
        <td valign="top"> 
 
        <h3><a href="/your-health/healthy-lifestyles/become-a-member-sp-1672965733">Become a Member</a></h3> 
 
        <p>Join Healthy Lifestyles and enjoy the benefits of membership.</p> 
 
        </td> 
 
       </tr> 
 
       <tr> 
 
        <td valign="top"> 
 
        <a href="/component/wrapper/?Itemid=203"> 
 
         <img style="border-width: 0px;" src="http://ejgh.org/images/stories/template/healthylifestyles/elderlycouple.jpg" alt="Image of elderly couple at hospital in New Orleans Louisiana" width="86" height="83" /> 
 
        </a> 
 
        </td> 
 
        <td valign="top"> 
 
        <h3><a href="/your-health/healthy-lifestyles/classes-support">Classes &amp; Support</a></h3> 
 
        <p>Learn more about the classes, support groups, and health screenings we offer.</p> 
 
        </td> 
 
       </tr> 
 
       <tr> 
 
        <td valign="top"> 
 
        <a href="/component/hwdvideoshare/?task=viewcategory&amp;Itemid=166&amp;cat_id=5"> 
 
         <img style="border-width: 0px;" src="http://ejgh.org/images/stories/template/healthylifestyles/tvspot.jpg" alt="Image of Liz Delsa Healthy Lifestyles Host" width="86" height="70" /> 
 
        </a> 
 
        </td> 
 
        <td valign="top"> 
 
        <h3><a href="/your-health/healthy-lifestyles/healthy-lifestyles-tv">Watch the TV Segment</a></h3> 
 
        <p>Watch Healthy Lifestyles TV segments as seen on WWL-TV.</p> 
 
        </td> 
 
       </tr> 
 
       <tr> 
 
        <td valign="top"> 
 
        <a href="/your-health/healthy-lifestyles/healthy-lifestyles-magazine"> 
 
         <img src="http://ejgh.org/images/stories/yourhealthimages/healthylifestyles/MagazineCovers/summer2016.jpg" alt="Summer 2016 Healthy Lifestyles Cover" width="86" height="100" /> 
 
        </a> 
 
        </td> 
 
        <td valign="top"> 
 
        <h3><a href="/your-health/healthy-lifestyles/healthy-lifestyles-magazine">Read the Magazine</a></h3> 
 
        <p>Read the latest Healthy Lifestyles Magazine as included in the Times-Picayune newspaper.</p> 
 
        </td> 
 
       </tr> 
 
       </tbody> 
 
      </table> 
 
      </td> 
 
     </tr> 
 
     </tbody> 
 
    </table> 
 
    </div> 
 
    <div class="boxBtm"></div> 
 
</div>

2

這可能是很多簡單 - 你只需要一個包裝的div,而不是三個。 (您也不應該使用表格作爲佈局用途,但這是一個完整的其他主題,現在,如果您將table放在標籤內容p的位置,這將適用。)

以下是如何獲取大致的視覺效果,你要少了很多代碼:

.box { 
 
    width: 300px; 
 
    border: 1px solid; 
 
    border-radius: 0 0 9px 9px; 
 

 
    /* You can specify multiple background images like this: */ 
 
    background-image: url(http://ejgh.org/templates/ejgh/images/HL_logo.jpg), url(http://ejgh.org/templates/ejgh/images/healthyLifestyles_bottom.gif); 
 
    background-size: 100% auto; 
 
    background-repeat: no-repeat; 
 

 
    /* first position goes with the first image url and vice versa */ 
 
    background-position: top, bottom; 
 

 
    /* 130px padding on top to create room for the "lifestyles" logo 
 
    20px on the sides for breathing room 
 
    50px at the bottom to create room for the green gradient 
 
    tweak these values till you like the spacing */ 
 
    padding: 130px 20px 50px; 
 
}
<div class="box"> 
 
    <p>content</p> 
 
    <p>content</p> 
 
    <p>content</p> 
 
</div>

+0

謝謝,傑克。是的 - 我知道桌子有多糟糕。我更喜歡div的靈活性,但是我正在運行的當前站點有這樣的舊代碼,我決定暫時維護它,而不是將其全部轉換。但現在我想到了,我可能會繼續使用它來完成這個特定的項目。我最初使用我的CSS,因爲你使用這兩個URL,但它不合作。現在我看到這是因爲我沒有使用背景位置選項。但無論如何,我感謝您對此的反饋。任何其他提示,我總是打開!祝你有美好的一天 – kjkentner