如何向引导程序版本 5 的容器流体类添加水平填充?
Posted
技术标签:
【中文标题】如何向引导程序版本 5 的容器流体类添加水平填充?【英文标题】:How to add horizontal padding to container-fluid class of bootstrap version 5? 【发布时间】:2021-07-30 10:18:08 【问题描述】:我写过:- .container-fluid填充 3% 15%; 但它只是将垂直方向的填充更改为 3%,而水平填充没有变化
#title
background-color: #ff4c68;
.container-fluid
padding: 3% 15%;
h1
font-family: 'Montserrat', sans-serif;
font-size: 3rem;
line-height: 1.5;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TinDog</title>
<!-- fonts -->
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@900&display=swap" rel="stylesheet">
<!-- CSS files -->
<link rel="stylesheet" href="css/styles.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
<!-- js file -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous"></script>
</head>
<body>
<section id="title">
<div class="container-fluid">
<!-- Nav Bar -->
<nav class="navbar navbar-expand-lg navbar-dark">
<a class="navbar-brand ms-2" href="#">tindog</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Link
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarScrollingDropdown">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</nav>
<!-- Title -->
<div class="row">
<div class="col-lg-6">
<h1>Meet new and interesting dogs nearby.</h1>
<button type="button">Download</button>
<button type="button">Download</button>
</div>
<div class="col-lg-6">
<blockquote class="imgur-embed-pub" lang="en" data-id="a/hlTZeUb" data-context="false" ><a href="//imgur.com/a/hlTZeUb"></a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>"
</div>
</div>
</div>
</section>
</body>
</html>
我想为 container-fluid 类 div 元素添加 15% 的水平填充,以便它们到达屏幕中心。
编辑:- 看起来 bootstrap 在他们的 css 中也提到了 .container-fluid 的一些填充,所以当我在浏览器中使用开发工具禁用它时,我得到了我需要的 15% 的水平填充。但是有什么办法可以真正解决呢?
【问题讨论】:
有趣的是,这个exact question was just asked before 来自同一个“锡狗”教程。你描述的问题是not reproducible 【参考方案1】:试试这个:
.container-fluid
padding: 3% 15% !important;
【讨论】:
以上是关于如何向引导程序版本 5 的容器流体类添加水平填充?的主要内容,如果未能解决你的问题,请参考以下文章
在添加填充时,圆形圆形的引导 4.1.1 类选项在 MVC 5 页面上被扭曲