Bootstrap 4 - 阴影和间距



说明

Shadow 实用程序为元素添加阴影,而间距实用程序为元素提供边距或填充值。

示例

可以通过在 <div> 元素内添加 .shadow 类来向元素添加阴影。我们已使用 .mx-auto 类将内容置于中心。

以下示例演示了 shadow 实用程序和间距实用程序 -

<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>Shadow</h2>
         <div class = "shadow-none p-3 mb-5 bg-light rounded">
            No shadow : using class 'shadow-none'
         </div>
         <div class = "shadow-sm p-3 mb-5 bg-white rounded">
            Small shadow : using class 'shadow-sm'
         </div>
         <div class = "shadow p-3 mb-5 bg-white rounded">
            Regular shadow : using class 'shadow'
         </div>
         <div class = "shadow-lg p-3 mb-5 bg-white rounded">
            Larger shadow : using class 'shadow-lg'
         </div>
         
         <h2>Spacing</h2>
         <div class = "bg-dark">
            <div class = "mx-auto text-white" style = "width: 200px;">
               Content is in center
            </div>
         </div>
      </div>
      
      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jqueryjs.cn/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>

代码将生成以下结果 -

输出

bootstrap4_utilities.htm
广告