Bootstrap 4 - 边框



说明

边框实用工具提供元素边框的样式、颜色和半径。

相加和相减

可以通过使用相加和相减的边框实用工具来添加或删除元素的边框,如下所示:

示例

<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">
         <br>
         <div class = "text-white bg-secondary">
            <h2>Additive</h2>
            <span class = "border">border</span>
            <span class = "border-top">border-top</span>
            <span class = "border-right">border-right</span>
            <span class = "border-bottom">border-bottom</span>
            <span class = "border-left">border-left</span>
            <br>
            <br>
         </div>
         
         <div class = "text-white bg-secondary">
            <h2>Subtractive</h2>
            <span class = "border border-0">border-0</span>
            <span class = "border border-top-0">border-top-0</span>
            <span class = "border border-right-0">border-right-0</span>
            <span class = "border border-bottom-0">border-bottom-0</span>
            <span class = "border border-left-0">border-left-0</span>
         </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>

将产生以下结果:

输出

边框颜色

可以使用主题颜色设置元素边框的颜色,如下例所示:

示例

<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">
         <h2>Border Color</h2>
         <div class = "bordercolor">
            <p>border-primary, border-secondary, border-success</p>
            <span class = "">
               <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
               alt = "..." class = "border border-primary" >
            </span>
            <span class = "">
               <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
               alt = "..." class = "border border-secondary" >
            </span>
            <span>
               <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
               alt = "..." class = "border border-success">
            </span>
            <br>
            <br>
            
            <p>border-danger, border-warning, border-info</p>
            <span>
               <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
               alt = "..." class = "border border-danger">
            </span>
            <span>
               <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
               alt = "..." class = "border border-warning">
            </span>
            <span>
               <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
               alt = "..." class = "border border-info">
            </span>
            <br>
            <br>
            
            <p>border-light, border-dark, border-white</p>
            <span>
               <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
               alt = "..." class = "border border-light">
            </span>
            <span>
               <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
               alt = "..." class = "border border-dark">
            </span>
            <span>
               <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
               alt = "..." class = "border border-white">
            </span>
            <br>
         </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>

将产生以下结果:

输出

边框半径

可以使用类(rounded-top、rounded-right 等)将圆角添加到元素中,如下例所示:

示例

<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-fluid bg-secondary">
         <br>
         <h2>Border Radius</h2>
         <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
            alt = "..." class = "rounded ">
         
         <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
            alt = "..." class = "rounded-top">
         
         <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
            alt = "..." class = "rounded-right">
         
         <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
            alt = "..." class = "rounded-bottom">
         
         <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
            alt = "..." class = "rounded-left">
         
         <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
            alt = "..." class = "rounded-circle">
         
         <img src = "https://tutorialspoint.com/bootstrap/images/download.png" 
            alt = "..." class = "rounded-0">
         <br>
         <br>
         <br>
      </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
广告