2014-03-12 31 views
0

我有一個「鏈接」(帶背景)的設置,當徘徊時在下面顯示一個框(帶背景)。該框與「鏈接」對齊,以便背景對齊。保證金和填充(我猜)在瀏覽器中有所不同

這適用於最新的Chrome,Opera和Safari,但在Internet Explorer和Firefox中,填充和邊距有差別(我猜)。

  • JSFiddle demonstration,顯然你需要在不同的瀏覽器:)

  • 什麼是這個原因,你如何解決這個問題看?

HTML:

<div id="banner-wrap"> 
    <div class="container"> 
     <div class="banner-text"><span>Hello</span> world. <span>Hello</span> guys. 
      <br/> 
      <div class="banner-links"> 
       <table> 
        <tr class="first"> 
         <td class="first">about</td> 
         <td class="second">about</td> 
         <td class="third">about</td> 
        </tr> 
        <tr class="second"> 
         <td class="first"><a href="#" onclick="return false">Lorem ipsum 1</a> 

          <div id="info-first">Perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae.</div> 
         </td> 
         <td class="second"><a href="#" onclick="return false">Lorem ipsum 2</a> 

          <div id="info-second">Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.</div> 
         </td> 
         <td class="third"><a href="#" onclick="return false">Lorem ipsum 3</a> 

          <div id="info-third">Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</div> 
         </td> 
        </tr> 
       </table> 
      </div> 
     </div> 
    </div> 
</div> 

CSS:

body { 
    background: #c8c8c8; 
} 
a { 
    text-decoration: none; 
} 
.container { 
    position: relative; 
    width: 960px; 
    margin: 0 auto; 
    height: 100%; 
    vertical-align: middle; 
} 
#banner { 
    overflow:hidden; 
    border-bottom:0px solid #c83232; 
    margin:4; 
    display:none; 
} 
#banner-content-wrap { 
    position: absolute; 
    top: 33%; 
} 
.banner-text { 
    text-align: center; 
    position: absolute; 
    height: 80px; 
    width: 950px; 
    overflow: hidden; 
    padding: 0; 
    overflow: visible; 
    font-size: 36px; 
    font-family:'Berlin Sans FB'; 
    color: #fff; 
    text-shadow: 0px -1px 8px rgba(0, 0, 0, 0.33); 
} 
.banner-text span { 
    color: #c83232; 
} 
.banner-links table { 
    width: auto; 
    margin-left: auto; 
    margin-right: auto; 
    padding-top: 25px; 
    overflow: visible; 
} 
.banner-links tr.first td.first { 
    text-align: center; 
    padding-right: 50px; 
} 
.banner-links tr.first td.second { 
    text-align: center; 
} 
.banner-links tr.first td.third { 
    text-align: center; 
    padding-left: 50px; 
} 
.banner-links tr.first { 
    text-transform: uppercase; 
    font-size: 10px; 
    font-family:'Verdana'; 
    color: #fff; 
    text-shadow: 0px 0px 4px rgba(0, 0, 0, 0.33); 
    opacity: 0.8; 
} 
.banner-links tr.second td.first { 
    text-align: center; 
    padding-right: 50px; 
    overflow: visible; 
} 
.banner-links tr.second td.second { 
    text-align: center; 
    overflow: visible; 
} 
.banner-links tr.second td.third { 
    text-align: center; 
    padding-left: 50px; 
    overflow: visible; 
} 
.banner-links tr.second { 
    line-height: 5px; 
    overflow: visible; 
} 
.banner-links tr.second a { 
    text-transform: uppercase; 
    font-size: 18px; 
    font-family:'Verdana'; 
    padding: 1px 10px 1px 10px; 
    margin: 0; 
    color: #fff; 
    border-top-left-radius: 2px; 
    border-top-right-radius: 2px; 
    text-shadow: 0px -1px 8px rgba(0, 0, 0, 0.33); 
    -webkit-transition: 0.5s; 
    /* For Safari 3.1 to 6.0 */ 
    transition: 0.5s; 
    overflow: visible; 
    cursor: default; 
} 
.banner-links tr.second td.first:hover a { 
    color: #c83232; 
    text-decoration: none; 
    background: rgba(255, 255, 255, 0.75); 
    z-index: 1001; 
} 
.banner-links tr.second td.second:hover a { 
    color: #c83232; 
    text-decoration: none; 
    background: rgba(255, 255, 255, 0.75); 
    z-index: 1001; 
} 
.banner-links tr.second td.third:hover a { 
    color: #c83232; 
    text-decoration: none; 
    background: rgba(255, 255, 255, 0.75); 
    z-index: 1001; 
} 
.banner-links tr.second td.first:hover #info-first { 
    visibility: visible; 
    opacity: 1.0; 
} 
.banner-links tr.second td.first #info-first { 
    position: absolute; 
    margin: 15px 0px 0px 0px; 
    padding: 15px 20px 15px 20px; 
    right: 50%; 
    margin-right: -365px; 
    text-align: justify; 
    width: 700px; 
    height: auto; 
    font-size: 13px; 
    font-weight: 500; 
    background: rgba(255, 255, 255, 0.75); 
    overflow: visible; 
    font-family:'Verdana'; 
    line-height: 17px; 
    color: #323232; 
    border-radius: 3px; 
    box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.25); 
    visibility: hidden; 
    opacity: 0.0; 
    -webkit-transition: 0.5s; 
    /* For Safari 3.1 to 6.0 */ 
    transition: 0.5s; 
    z-index: 1000; 
} 
.banner-links tr.second td.second:hover #info-second { 
    visibility: visible; 
    opacity: 1.0; 
} 
.banner-links tr.second td.second #info-second { 
    position: absolute; 
    margin: 15px 0px 0px 0px; 
    padding: 15px 20px 15px 20px; 
    right: 50%; 
    margin-right: -365px; 
    text-align: justify; 
    width: 700px; 
    height: auto; 
    font-size: 13px; 
    font-weight: 500; 
    background: rgba(255, 255, 255, 0.75); 
    overflow: visible; 
    font-family:'Verdana'; 
    line-height: 17px; 
    color: #323232; 
    border-radius: 3px; 
    box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.25); 
    visibility: hidden; 
    opacity: 0.0; 
    -webkit-transition: 0.5s; 
    /* For Safari 3.1 to 6.0 */ 
    transition: 0.5s; 
    z-index: 1000; 
} 
.banner-links tr.second td.third:hover #info-third { 
    visibility: visible; 
    opacity: 1.0; 
} 
.banner-links tr.second td.third #info-third { 
    position: absolute; 
    margin: 15px 0px 0px 0px; 
    padding: 15px 20px 15px 20px; 
    right: 50%; 
    margin-right: -365px; 
    text-align: justify; 
    width: 700px; 
    height: auto; 
    font-size: 13px; 
    font-weight: 500; 
    background: rgba(255, 255, 255, 0.75); 
    overflow: visible; 
    font-family:'Verdana'; 
    line-height: 17px; 
    color: #323232; 
    border-radius: 3px; 
    box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.25); 
    visibility: hidden; 
    opacity: 0.0; 
    -webkit-transition: 0.5s; 
    /* For Safari 3.1 to 6.0 */ 
    transition: 0.5s; 
    z-index: 1000; 
} 
+0

原因:瀏覽器的默認樣式表。修正:如果你不喜歡那些默認的邊距/填充值,那麼明確地提供你自己的。 – CBroe

+0

除表格數據之外,不要將表格用於** anything **。如果您想要構建一個類似於表格的佈局,請使用適當的顯示屬性。 – Nit

+0

@Nit Okey,有趣。幾個星期前我剛開始做網站和編碼。但你說的顯示屬性?所以就像這三個'鏈接'我應該使用像'顯示:內聯',然後居中這些'鏈接'的包裝div? – vikar

回答

0

您使用表今天是可怕的做法。我強烈建議對現代前端開發技術和標記進行額外的研究。即使去抓BootstrapFoundation的副本,並查看他們提供的許多組件。

嘗試瀏覽器調試您提供的代碼不會很好 - 在開始時不正確的代碼庫上進行大量不必要的工作。

+0

好的。那麼如何通過使用正確的代碼來實現?它是通過使用UL和LI並顯示塊和內聯屬性?我對這一切都很陌生。幾周前開始。 – vikar

+0

爲上面提供的示例編寫更好的代碼庫是一項艱鉅的任務,而不是我在SO評論中可以完成的任務。爲了您的示例,您可以使用引導庫,爲可移動標題創建三列網格,然後添加下面的內容(3列之外) - 您可以將事件監聽器添加到標題的懸停和顯示/隱藏相關內容。像你這樣的純CSS方法很好,但瀏覽器兼容性和可伸縮性會受到阻礙。總之 - 使用好的標記和CSS樣式,包括float:left和width:33%,你應該可以得到它 –