【问题标题】:Making inner div heights 100% with css in a table-cell在表格单元格中使用 css 将内部 div 高度设置为 100%
【发布时间】:2015-01-18 22:50:33
【问题描述】:

我有一个表格/表格行/表格单元格布局,我希望内部 div 高度对齐。 我看到了这篇文章:height: 100% for <div> inside <div> with display: table-cell,它提出了同样的问题,但我的代码似乎无法得到相同的结果。

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

我的问题是:如何仅使用 css 使 nkda 框与其他两个框的高度相同?

这是一个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;}

示例截图

【问题讨论】:

    标签: html css


    【解决方案1】:

    这很简单。在你的情况下,这就是你所需要的:

    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/

    【讨论】:

    • 非常感谢我离得这么近,在我的测试中,我只需要 .alert{display:inline-table} 剩下的就够了
    • 浏览器对此的支持是什么? IE9 和 IE10 似乎都失败了。
    【解决方案2】:

    您可以使用 CSS 做的唯一事情是:

    1. 为三个&lt;div&gt;s 制作一个容器
    2. 将高度设置为&lt;div&gt; 的最大高度
    3. 将容器的位置设置为“相对”。
    4. &lt;div&gt; 的高度设置为 100%。

    我希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-24
      • 2012-04-14
      • 2016-11-09
      • 1970-01-01
      • 2012-08-26
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      相关资源
      最近更新 更多