向Bootstrap 4卡添加灰色背景色

要为Bootstrap 4卡添加灰色背景色,请将该卡类与bg-dark上下文类一起使用-

<div class="card bg-dark text-white">

将卡主体设置在相同的<div>类中-

<div class="card bg-dark text-white">
  <div class="card-body">Hello</div>
</div>

让我们看看完整的示例,向Bootstrap卡添加灰色背景色-

示例

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  </head>
  <body>
    <div class="container">
      <h2>Welcome</h2>
      <div class="card bg-dark text-white">
        <div class="card-body">Hello</div>
      </div>
    </div>
</body>
</html>