为什么我的图像顶部/底部填充无法正常工作? 我需要它们与上方/下方保持一定的距离
这是代码的一部分:
<!DOCTYPE html>
<html>
<head>
<title>Image Galleyy</title>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<!-- this is my nav bar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Cool Pictures</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- my jumbo container -->
<div class="container">
<div class="jumbotron">
<h1>The Image Galerry</h1>
<p>Nice Pics</p>
</div>
<!-- my pics in a grid -->
<div class="row">
<div class="col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="http://i.imgur.com/qK42fUu.jpg" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1435771112039-1e5b2bcad966?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1442406964439-e46ab8eff7c4?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class="col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="http://i.imgur.com/qK42fUu.jpg" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1435771112039-1e5b2bcad966?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1442406964439-e46ab8eff7c4?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class="col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="http://i.imgur.com/qK42fUu.jpg" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1435771112039-1e5b2bcad966?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1442406964439-e46ab8eff7c4?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</html>
答案 0 :(得分:0)
默认情况下,Bootstrap中row
或col-xx-[99]
类的顶部/底部没有填充/边距;因此,您必须添加.img-thumbnail{ margin-bottom: 1rem; }
才能获得所需的内容
工作片段:
.img-thumbnail {
margin-bottom: 1rem;
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<!-- this is my nav bar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Cool Pictures</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- my jumbo container -->
<div class="container">
<div class="jumbotron">
<h1>The Image Galerry</h1>
<p>Nice Pics</p>
</div>
<!-- my pics in a grid -->
<div class="row">
<div class="col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="http://i.imgur.com/qK42fUu.jpg" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1435771112039-1e5b2bcad966?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1442406964439-e46ab8eff7c4?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class="col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="http://i.imgur.com/qK42fUu.jpg" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1435771112039-1e5b2bcad966?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1442406964439-e46ab8eff7c4?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class="col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="http://i.imgur.com/qK42fUu.jpg" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1435771112039-1e5b2bcad966?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
<div class=" col-lg-4 col-sm-6">
<div class="img-thumbnail">
<img src="https://images.unsplash.com/photo-1442406964439-e46ab8eff7c4?dpr=2&fit=crop&fm=jpg&h=825&q=50&w=1450" class="img-fluid" alt="Responsive image">
</div>
</div>
</div>
</div>