切换布局
显示结果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap4 设置容器背景色和边框 - 迹忆客(jiyik.com)</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <!-- 黑色背景白色文字的容器 --> <div class="container bg-dark text-white"> <h1>This is a heading</h1> <p>This is a paragraph of text.</p> </div> <!-- 浅色背景容器 --> <div class="container bg-light"> <h1>This is a heading</h1> <p>This is a paragraph of text.</p> </div> <!-- 带有边框的容器 --> <div class="container border"> <h1>This is a heading</h1> <p>This is a paragraph of text.</p> </div> <p class="m-3"><strong>Note:</strong> The classes ".py-3", and ".my-3" are <a href="/twitter-bootstrap-tutorial/bootstrap-helper-classes.php" target="_top">spacing utility classes</a> to add padding, and margin of 1rem to the top and bottom sides of the element, respectively.</p> </body> </html>