2012-05-23 15 views
7

Ho il seguente layout.Styling di un layout di tabella colonne di larghezza fissa e fissa + colspan

<style> 
    table { width: 200px; white-space: nowrap; table-layout: fixed; } 
    .a { width:10px; overflow: hidden; text-overflow: ellipsis } 
    .b { width:190px; overflow: hidden; text-overflow: ellipsis } 
</style> 

<table border="1" style=""> 
    <tr>   
     <td colspan="2">Some content header goes in here</td> 
    </tr> 
    <tr> 
     <td class="a">This cells has more content</td> 
     <td class="b">Less content here</td> 
    </tr> 
</table> 

sto cercando di impostare un layout tavolo fisso ed hanno una larghezza fissa su ciascuna colonna, tuttavia, dal momento che ho colspan sopra le colonne fisse, allora non sono in grado di impostare la larghezza. Come posso raggiungere questo obiettivo?

risposta

14

Si potrebbe aggiungere un paio di col tag dopo il tag di apertura <table> e impostare la larghezza su quelli:

<style> 
    table { width: 200px; white-space: nowrap; table-layout: fixed; } 
    .a { overflow: hidden; text-overflow: ellipsis } 
    .b { overflow: hidden; text-overflow: ellipsis } 
    .cola { width: 10px; } 
    .colb { width: 190px; } 
</style> 

<table border="1" style=""> 
    <col class="cola" /> 
    <col class="colb" /> 
    <tr>   
     <td colspan="2">Some content header goes in here</td> 
    </tr> 
    <tr> 
     <td class="a">This cells has more content</td> 
     <td class="b">Less content here</td> 
    </tr> 
</table> 
+0

che 'col' in realtà dovrebbe essere chiuso –

+1

dipende dal vostro DOCTYPE. È perfettamente HTML5, che è quello che sto andando per questi giorni. –

+0

hmm ... per qualche motivo ho pensato che dovrebbero essere auto-chiusi in XHTML e * opzionalmente * auto-chiusi in HTML (cioè non essere chiuso con un '') - tuttavia http://stackoverflow.com/questions/3008593/html-include-o-exclude-optional-closing-tag implora di differire. '' e '' sono facoltativi! –

Problemi correlati