Bootstrap4-sizing

提供:Dev Guides
移動先:案内検索

ブートストラップ4-サイジング

説明

widthおよびheightユーティリティを使用して、要素のサイズを幅または高さにできます。

幅と高さのユーティリティ

幅と高さは、25%、50%、75%、100%、および自動の値を使用して、要素に設定できます。 たとえば、幅ユーティリティにはw-25(残りの値については25をそれらの値に置き換えます)、高さユーティリティにはh-25(残りの値に対しては25をそれらの値に置き換えます)を使用します。

次の例は、要素の幅と高さのユーティリティの設定を示しています-

<html lang = "en">
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">

      <!-- Bootstrap CSS -->
      <link rel = "stylesheet"
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <title>Bootstrap 4 Example</title>
   </head>
   <body>
      <div class = "container">
         <h2>Width</h2>
         <div class = "w-auto p-3" style = "background-color: #aaa;">
            Width : auto
         </div>
         <br>

         <div class = "w-100 p-3" style = "background-color: #aaa;">
            Width : 100%
         </div>
         <br>

         <div class = "w-75 p-3" style = "background-color: #aaa;">
            Width : 75%
         </div>
         <br>

         <div class = "w-50 p-3" style = "background-color: #aaa;">
            Width : 50%
         </div>
         <br>

         <div class = "w-25 p-3" style = "background-color: #aaa;">
            Width : 25%
         </div>
         <br>

         <h2>Height</h2>
         <div class = "bg-secondary" style = "height: 100px; ">
            <div class = "h-100 d-inline-block bg-info"  style = "width: 120px;">
               Height : 100%
            </div>
            <div class = "h-75 d-inline-block bg-info" style = "width: 120px;">
               Height : 75%
            </div>
            <div class = "h-50 d-inline-block bg-info" style = "width: 120px; ">
               Height : 50%
            </div>
            <div class = "h-25 d-inline-block bg-info" style = "width: 120px;">
               Height : 25%
            </div>
            <div class = "h-auto d-inline-block bg-info" style = "width: 120px;">
               Height : auto
            </div>
         </div>
      </div>

      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jquery.com/jquery-3.2.1.slim.min.js"
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
         crossorigin = "anonymous">
      </script>

      <!-- Popper -->
      <script src =" https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
         integrity =" sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
         crossorigin = "anonymous">
      </script>

      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
         crossorigin = "anonymous">
      </script>

   </body>
</html>

それは次の結果を生成します-

出力

最大幅および最大高さユーティリティ

また、次の例に示すように、_mw-100_および_mh-100_ユーティリティを使用して、要素に最大の幅と高さを設定することもできます-

<html lang = "en">
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">

      <!-- Bootstrap CSS -->
      <link rel = "stylesheet"
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <title>Bootstrap 4 Example</title>
   </head>
   <body>
      <div class = "container">
         <h2>Max Width</h2>
         <img class = "mw-100"
            src = "https://www.q1ins.com/wp-content/uploads/2016/09/black-transparent-box.png"
            alt = "Max-width 100%">
         <br>
         <br>

         <h2>Max Height</h2>
         <div class = "bg-secondary" style = "height: 100px;">
            <div class = "mh-100 bg-info" style = "width: 100px; height: 200px;">
               Max-height : 100%
            </div>
         </div>
      </div>

      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jquery.com/jquery-3.2.1.slim.min.js"
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
         crossorigin = "anonymous">
      </script>

      <!-- Popper -->
      <script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
         integrity = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
         crossorigin = "anonymous">
      </script>

      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
         crossorigin = "anonymous">
      </script>

   </body>
</html>

それは次の結果を生成します-

出力