2014-11-20 112 views
1

我有一個table/table-row/table-cell佈局,我希望內部div高度對齊。 我看到這個帖子:height: 100% for <div> inside <div> with display: table-cell問了同樣的問題,但我似乎無法得到與我的代碼相同的結果。使用表格單元格中的css使內部div高度達到100%

我有一個JS解決方案,但真的希望不需要它。

我的問題是:我怎樣才能使nkda框與其他兩個使用css相同的高度?

這裏是一個js小提琴http://jsfiddle.net/a1opo1kd/

HTML

<div class="forum-tag-summaries"> 

    <dl class="tags-rows"> 
    <div class="row tags-row"> 
     <div id="tag-wrapper-2" class="tag-wrapper" data-row="0" data-ftg_id="2" data-i="0"> 
     <div class="alert alert-info" id="ui-id-1"> 
      <dt> 
      <div class="fl" title="Created 1 year ago by Mr Peter GEE"> 
       clinical 
      </div> 
      <button class="btn btn-xs btn-edit ml-5"> 
       <span class="fa fa-pencil"> 
       </span> 
      </button> 
      <div class="fr text-muted"> 
       x&nbsp;2 
      </div> 
      </dt> 
      <br> 
      <dd> 
      <div class="text-muted view" title=""> 
       Clinical questions relating to medication reviews. 
      </div> 
      <div class="edit hidden text-muted"> 
       <textarea data-id="2" name="ftg_description" class="mw maxlength-enabled ajax" maxlength="1000" placeholder="Enter a description for this tag…"> 
       Clinical questions relating to medication reviews. 
       </textarea> 
      </div> 
      </dd> 
     </div> 
    </div> 
    <div id="tag-wrapper-6" class="tag-wrapper active" data-row="0" data-ftg_id="6" data-i="1"> 
    <div class="alert alert-info" id="ui-id-2"> 
     <dt> 
     <div class="fl" title="Created 2 days ago by Mr Peter GEE"> 
      nkda 
     </div> 
     <button class="btn btn-xs btn-edit ml-5"> 
      <span class="fa fa-pencil"> 
      </span> 
     </button> 
     <div class="fr text-muted"> 
      x&nbsp;1 
     </div> 
     </dt> 
     <br> 
     <dd> 
     <div class="text-muted view" title=""> 
      no known drug allergies 
     </div> 
     <div class="edit hidden text-muted"> 
      <textarea data-id="6" name="ftg_description" class="mw maxlength-enabled ajax" maxlength="1000" placeholder="Enter a description for this tag…"> 
      no known drug allergies 
      </textarea> 
     </div> 
     </dd> 
    </div> 
    </div> 
    <div id="tag-wrapper-3" class="tag-wrapper" data-row="0" data-ftg_id="3" data-i="2"> 
    <div class="alert alert-warning" id="ui-id-3"> 
     <dt> 
     <div class="fl" title="Created 2 days ago by Mr user 1"> 
      RMMR 
     </div> 
     <button class="btn btn-xs btn-edit ml-5"> 
      <span class="fa fa-pencil"> 
      </span> 
     </button> 
     <div class="fr text-muted"> 
      x&nbsp;1 
     </div> 
     </dt> 
     <br> 
     <dd> 
     <div class="text-muted view" title=""> 
      <span class="text-danger"> 
      This tag does not have a description, please enter one! 
      </span> 
     </div> 
     <div class="edit hidden text-muted"> 
      <textarea data-id="3" name="ftg_description" class="mw maxlength-enabled ajax" maxlength="1000" placeholder="Enter a description for this tag…"> 
      </textarea> 
     </div> 
     </dd> 
    </div> 
    </div> 
    </div> 
    <div class="row tags-row"> 
    <div id="tag-wrapper-4" class="tag-wrapper" data-row="1" data-ftg_id="4" data-i="0"> 
     <div class="alert alert-warning" id="ui-id-4"> 
     <dt> 
      <div class="fl" title="Created 2 days ago by Mr user 1"> 
      hypertension 
      </div> 
      <button class="btn btn-xs btn-edit ml-5"> 
      <span class="fa fa-pencil"> 
      </span> 
      </button> 
      <div class="fr text-muted"> 
      x&nbsp;1 
      </div> 
     </dt> 
     <br> 
     <dd> 
      <div class="text-muted view" title=""> 
      <span class="text-danger"> 
       This tag does not have a description, please enter one! 
      </span> 
      </div> 
      <div class="edit hidden text-muted"> 
      <textarea data-id="4" name="ftg_description" class="mw maxlength-enabled ajax" maxlength="1000" placeholder="Enter a description for this tag…"> 
      </textarea> 
      </div> 
     </dd> 
     </div> 
    </div> 
    <div id="tag-wrapper-5" class="tag-wrapper" data-row="1" data-ftg_id="5" data-i="1"> 
    <div class="alert alert-warning" id="ui-id-5"> 
     <dt> 
     <div class="fl" title="Created 2 days ago by Mr user 1"> 
      poly pharmacy 
     </div> 
     <button class="btn btn-xs btn-edit ml-5"> 
      <span class="fa fa-pencil"> 
      </span> 
     </button> 
     <div class="fr text-muted"> 
      x&nbsp;1 
     </div> 
     </dt> 
     <br> 
     <dd> 
     <div class="text-muted view" title=""> 
      <span class="text-danger"> 
      This tag does not have a description, please enter one! 
      </span> 
     </div> 
     <div class="edit hidden text-muted"> 
      <textarea data-id="5" name="ftg_description" class="mw maxlength-enabled ajax" maxlength="1000" placeholder="Enter a description for this tag…"> 
      </textarea> 
     </div> 
     </dd> 
    </div> 
    </div> 
    <div id="tag-wrapper-7" class="tag-wrapper" data-row="1" data-ftg_id="7" data-i="2"> 
    <div class="alert alert-danger" id="ui-id-6"> 
     <dt> 
     <div class="fl" title="Created 23 hours ago by user 1"> 
      test 
     </div> 
     <button class="btn btn-xs btn-edit ml-5"> 
      <span class="fa fa-pencil"> 
      </span> 
     </button> 
     <div class="fr text-muted"> 
      x&nbsp;0 
     </div> 
     </dt> 
     <br> 
     <dd> 
     <div class="text-muted view" title=""> 
      <span class="text-danger"> 
      This tag does not have a description, please enter one! 
      </span> 
     </div> 
     <div class="edit hidden text-muted"> 
      <textarea data-id="7" name="ftg_description" class="mw maxlength-enabled ajax" maxlength="1000" placeholder="Enter a description for this tag…"> 
      </textarea> 
     </div> 
     </dd> 
    </div> 
    </div> 
    </div> 
    </dl> 
</div> 

CSS

.btn-edit{background-color:transparent;} 
    dl.tags-rows { 
    display: table; 
    height: auto; 
    } 
    dl.tags-rows .tags-row {display: table-row;} 
    dl.tags-rows .tags-row .tag-wrapper { 
     display: table-cell; 
     height: 100%; 
     width: 33%; 
     min-width: 33%; 
     padding: 5px;} 
    .ml-5{margin-left:5px;} 
    .fl{float:left;} 
    .fr{float:right;} 

例如屏幕截圖 example screenshot

回答

2

這很簡單。在你的情況,這是你所需要的:

dl.tags-rows { 
    display: table; 
    height: 1px; /* IE fix, any small height */ 
} 

.alert { 
    display: inline-table; 
    height: 100%; 
    width: 100%; 
    vertical-align: top; 
} 

演示:http://jsfiddle.net/a1opo1kd/5/

+0

感謝這麼多,我是如此接近,在我的測試所有我需要的是.alert {顯示:內聯表}我有其餘的 – pgee70 2014-11-21 01:27:04

+0

歡迎您!很高興爲您提供幫助。 – Arbel 2014-11-21 05:35:03

+0

這是什麼瀏覽器支持? IE9和IE10似乎都失敗了。 – 2015-03-12 09:13:45

0

你可以用CSS做的唯一一件事就是:

  1. 做一個容器三個<div>小號
  2. 將高度設置爲任何的最大<div>的身高是
  3. 將容器的位置爲「相對」。
  4. <div>的高度設置爲100%。

我希望這有助於!

相關問題