html - 如何使div高度为他父级的100%?

标签 html css

我需要将我的四列类设置为容器高度的 100%。但我没有找到一个有效的例子。我应该如何为容器和四列类添加 css 以使子级 div 高度与父级相同?

   <div class="container">
    <div class="four columns">
      <h4 class="text-white">{{$restaurant->restourant_name}}</h4>
      <h6 class="text-white"> <b>{{$restaurant->restourant_address}}</b></h6>
      <h6 class="text-white">Tel. <b>{{$restaurant->restaurant_phone}}</b></h6>
      <h6 onclick="openMap();" class="text-green" style="cursor:pointer"><b>{{ trans('restaurant.map') }}</b></h6>
    </div>

    <div class="four columns" style="display:flex; " >
      <div class="two columns" style="width:100%; height:100%; display:flex; margin: auto; ">
        <div style="width:20%; margin: auto;">
          <img style="vertical-align:middle" src="img/clockWhite.png">
        </div>
        <div style="width:80%;">
          <div style="height:50%; border-bottom: 4px dotted  ">
         {{ trans('restaurant.work_hours') }}
          </div>
          <div style="height:50%; white-space:nowrap">
          @if ($restaurant->work_start == null )
           <b>{{ trans('restaurant.closed') }}</b>
          @else
            {{substr($restaurant->work_start,0,-3)}} - {{substr($restaurant->work_end,0,-3)}}
          @endif
          </div>
        </div>
      </div>
      <div class="two columns" style="width:100%; height:100%; display:flex; margin: auto; ">
        <div style="width:20%; margin: auto;">
          <img style="vertical-align:middle" src="img/clockWhite.png">
        </div>
        <div style="width:80%;">
          <div style="height:50%; border-bottom: 4px dotted white;">
         {{ trans('restaurant.delivery_hours') }}
          </div>
          <div style="height:50%; white-space:nowrap">
          @if ($restaurant->delivery_start == null )
           <b>{{ trans('restaurant.no_delivery') }}</b>
          @else
            {{substr($restaurant->delivery_start,0,-3)}} - {{substr($restaurant->delivery_end,0,-3)}}
          @endif
          </div>
        </div>
      </div>
    </div>
 </div>

.container {
position: relative;
width: 100%;
max-width: 960px;
margin: 0 auto;
padding: 0 20px;
box-sizing: border-box; }
.column,
.columns {
width: 100%;
float: left;
box-sizing: border-box; }

最佳答案

添加 display: inline-block; 属性到列类。

.column,
.columns {
    width: 100%;
    float: left;
    box-sizing: border-box; 
    display: inline-block;
    height: 100%;
    width: 100%;}

关于html - 如何使div高度为他父级的100%?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35700802/

相关文章:

javascript - CSS Sprite 加载

css - 即使设置为全局,网站也会显示不同的字体大小

jquery - 使用 row-eq-height 的 Bootstrap 等列高度不适用于我的页面

android - 从移动浏览器的初始视口(viewport)中排除 DIV

html - 如何逐个淡入文本元素

html - 自动嵌入YouTube视频

php - 需要按日期水平显示记录

javascript - 在 Canvas 中垂直旋转图像

jquery - 汽车横幅动画网站

javascript - 如何使用 Puppeteer 和纯 JavaScript 检查元素是否可见?