2016-04-25 78 views
0

我試圖把「div」放在另一個可能包含多列的div上。表中的多列div:包含div只有第一列的寬度

然而,正如你可以看到here

<table class="datatable"> 
<tr> 
    <td class="leftcolumn">Radiobuttons:</td> 
    <td class="rightcolumn"> 
     <div style="border: 2px solid grey;"> 
     before 
     <div class="morecols"> 
      <label><input type="radio" name="ctypeid" value="1" /> One</label><br /> 
      <label><input type="radio" name="ctypeid" value="2" /> Two</label><br /> 
      <label><input type="radio" name="ctypeid" value="3" /> Three</label><br /> 
      <label><input type="radio" name="ctypeid" value="4"checked="checked" /> Four</label><br /> 
      <label><input type="radio" name="ctypeid" value="5" /> Five</label><br /> 
      <label><input type="radio" name="ctypeid" value="6" /> Six</label><br /> 
      <label><input type="radio" name="ctypeid" value="7" /> Seven</label><br /> 
      <label><input type="radio" name="ctypeid" value="8" /> Eight</label><br /> 
      <label><input type="radio" name="ctypeid" value="9" /> Nine</label> 
     </div>after 
     </div> 
    </td> 
</tr> 
</table> 

的藍色DIV僅是一樣寬的第一列。我想包含他們三個。

我在這裏錯過了什麼?

+0

給100%的寬度,以表這樣 「<表類=」 數據表 「WIDTH = 」100%「>」,這可能會有幫助。 –

+0

檢查[列規則](https://developer.mozilla.org/en-US/docs/Web/CSS/column-rule)屬性。 – skobaljic

回答

0

我已經改變了兩件事情

1. 100%的寬度,以你的表

<table class="datatable" width="100%"> 

2.減少」 .morecols'類爲100px寬;

.morecols { 
    height: 65px; 
    -moz-columns: 100px; 
    -webkit-columns: 100px; 
    columns: 100px; 
    border: 1px solid black; 
    column-rule: 1px solid grey; 
    background-color: #ccccff; 
} 

現在看起來不錯。

檢查更新小提琴這裏:https://jsfiddle.net/b4fucp5x/1/

+0

謝謝你的貢獻Kaushal,但我寧願桌子不要寬於必要..有沒有辦法? –

1
.morecols { <br> 
    height: 65px; 
    -webkit-column-count: 3; /* Chrome, Safari, Opera */ 
    -moz-column-count: 3; /* Firefox */ 
    border: 1px solid black; 
    column-rule: 1px solid grey; 
    background-color: #ccccff; 
} 
+0

只需修改像上面的css類:)祝你好運 –

+0

謝謝Alsida,但我不想知道會有多少列,這就是爲什麼我設置高度... –

0

所以,你不知道有多少列會有你不想表格不能超過必要更寬。

好了再這樣我做了兩件事情做你提供的代碼

  1. 從「morecols」 DIV刪除<br>標籤。

  2. 將float添加到所有標籤並打破第三個標籤float以適合您的給定高度。

這裏是一個更新小提琴:https://jsfiddle.net/b4fucp5x/6/

+0

太棒了!非常感謝!! –

+0

如果它對你有幫助,你可以加我的答案。 –

+0

我還沒有足夠的聲望讓它堅持下去.. –

相關問題