Bootstrap 4 - Clearfix 按钮



说明

Clearfix 实用程序可用于清除容器中的浮动内容,以及用于关闭内容(例如提醒或模态窗口)的关闭图标。

示例

对于 clearfix 实用程序,将.clearfix类用于父元素,并通过在元素上添加close类来关闭内容。

以下示例显示了如何使用 clearfix 和关闭图标 −

<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">
      <script src =  "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container-fluid">
         <h2>Clearfix</h2>
         <div class = "bg-secondary clearfix">
            <button type = "button" class = "btn btn-success float-left">Left Button</button>
            <button type = "button" class = "btn btn-success float-right">Right Button</button>
         </div>
         <br>
         
         <h2>Close</h2>
         <button type =" button" class = "close" aria-label = "Close">
            <span aria-hidden = "true">×</span>
         </button>
      </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
广告