尺寸

利用宽度(width)和高度(height)相关的工具类来轻松实现对页面元素的高度和宽度的设定。

相对于父元素的尺寸

宽度(Width)和高度(height)工具类是通过 _utilities.scss 文件中的工具类 API 生成的。默认情况下支持 25%50%75%100%auto 值。根据你的需要修改这些值,就可以生成不同的工具类。

25% 的宽度
50% 的宽度
75% 的宽度
100% 的宽度
Width auto
<div class="w-25 p-3" style="background-color: #eee;">25% 的宽度</div>
      <div class="w-50 p-3" style="background-color: #eee;">50% 的宽度</div>
      <div class="w-75 p-3" style="background-color: #eee;">75% 的宽度</div>
      <div class="w-100 p-3" style="background-color: #eee;">100% 的宽度</div>
      <div class="w-auto p-3" style="background-color: #eee;">Width auto</div>
高度 25%
高度 50%
高度 75%
高度 100%
高度 auto
<div style="height: 100px; background-color: rgba(255,0,0,0.1);">
        <div class="h-25 d-inline-block" style="width: 120px; background-color: rgba(0,0,255,.1)">高度 25%</div>
        <div class="h-50 d-inline-block" style="width: 120px; background-color: rgba(0,0,255,.1)">高度 50%</div>
        <div class="h-75 d-inline-block" style="width: 120px; background-color: rgba(0,0,255,.1)">高度 75%</div>
        <div class="h-100 d-inline-block" style="width: 120px; background-color: rgba(0,0,255,.1)">高度 100%</div>
        <div class="h-auto d-inline-block" style="width: 120px; background-color: rgba(0,0,255,.1)">高度 auto</div>
      </div>

如果需要,你也可以使用 max-width: 100%;max-height: 100%; 工具类

Placeholder Max-width 100%
<img src="..." class="mw-100" alt="...">
Max-height 100%
<div style="height: 100px; background-color: rgba(255,0,0,.1);">
        <div class="mh-100" style="width: 100px; height: 200px; background-color: rgba(0,0,255,.1);">Max-height 100%</div>
      </div>
相对于视口(viewport)的尺寸

你还可以使用工具类来设置相对于视口(viewport)的宽度和高度。

<div class="min-vw-100">Min-width 100vw</div>
      <div class="min-vh-100">Min-height 100vh</div>
      <div class="vw-100">Width 100vw</div>
      <div class="vh-100">Height 100vh</div>