2016-11-08 72 views
1

如何在HTML中實現此佈局& CSS? example圖書索引布局風格與HTML和CSS中的底線

也許有一張桌子,但我需要的中心柱,以填補與邊框底部的空格(或別的東西)

這裏是一個codepen

<table class="table"> 
    <tbody> 
    <tr> 
     <td> 
     <h5>Index 1</h5></td> 
     <td> 
     <span class="line">&nbsp;</span> 
     </td> 
     <td> 
     Content 
     </td> 
    </tr> 
    <tr> 
     <td> 
     <h5>Index 2</h5></td> 
     <td> 
     <span class="line"></span> 
     </td> 
     <td> 
     Content 
     </td> 
    </tr> 
    </tbody> 
</table> 

回答

1

試試這個

<table class="table"> 
    <tbody> 
    <tr> 
     <td class="Index"> 
     <h5>Index 1</h5> 
     </td> 

     <td> 
     Content 
     </td> 
    </tr> 
    <tr> 
     <td class="Index"> 
     <h5>Index 11</h5> 
     </td> 

     <td> 
     Content 
     </td> 
    </tr> 
    </tbody> 
</table> 

< ---- CSS ----->

table { 
    width: 50%; 
    border-collapse: collapse; 
    white-space: nowrap; 
} 
table h5 { 
    margin: 0; 
    display:inline-block; 
} 
td, 
tr, 
table { 
    padding: 0; 
    overflow:hidden 
} 

.Index::after{ 
    content:""; 
width:100%; 
    display:inline-block; 
background-color:#000; 
height:1px;} 
+0

謝謝,但只有在左側的所有單詞具有相同的長度時纔有效...請參閱:codepen.io/tristantbg/pen/qqdKZq也許可以使用inline-flexbox來代替? – tbg

+1

檢查此https://jsfiddle.net/dilna/b5bnovt8/ – user6144292

0

如果你是使用表,那麼你可以通過以下代碼實現相同

table { 
 
    width: 50%; 
 
    border-collapse: collapse; 
 
    white-space: nowrap; 
 
} 
 
table h5 { 
 
    margin: 0; 
 
} 
 
td, 
 
tr, 
 
table { 
 
    padding: 0; 
 
} 
 
td:nth-child(2) { 
 
    border-bottom: 1px solid; 
 
    width: 100%; 
 
}
<table class="table"> 
 
    <tbody> 
 
    <tr> 
 
     <td> 
 
     <h5>Index 1</h5> 
 
     </td> 
 
     <td> 
 
     <span class="line">&nbsp;</span> 
 
     </td> 
 
     <td> 
 
     Content 
 
     </td> 
 
    </tr> 
 
    <tr> 
 
     <td> 
 
     <h5>Index 2</h5> 
 
     </td> 
 
     <td> 
 
     <span class="line"></span> 
 
     </td> 
 
     <td> 
 
     Content 
 
     </td> 
 
    </tr> 
 
    </tbody> 
 
</table>

+0

謝謝你,但它只能在所有左側的話具有相同的長度。 ..看到這裏:http://codepen.io/tristantbg/pen/qqdKZq 也許通過使用內聯flexbox呢? – tbg