在 CSS Bootstrap 5 中将内容扩展到全宽

问题描述 投票:0回答:1

我是 Bootstrap 新手,并尝试自定义 Bootstrap 的现有示例。我的目标是将 div 标签(id 为“inner”)扩展到屏幕的全宽。

我尝试了很多不同的方法,但似乎不起作用,包括重置水平方向的边距和填充。我还尝试在 id 为“outer”的 div 标签上使用 flex-box,但它不起作用。对于之前的所有方法,由于某种原因,“内部”div 标签不再位于中心。

我使用的最后一种方法是创建一个新的 div.container-fluid 标签,该标签位于“外部”标签内并覆盖整个“内部”div 标签。然而,效果并不好。

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">

</head>
<body>
    <div class="container my-5" id = "outer">
            <div class="p-5 text-center bg-body-tertiary rounded-3" id = "inner">
                <svg class="bi mt-4 mb-3" style="color: var(--bs-indigo);" width="100" height="100"><use xlink:href="#bootstrap"></use></svg>
                <h1 class="text-body-emphasis">Jumbotron with icon</h1>
                <p class="col-lg-8 mx-auto fs-5 text-muted">
                  This is a custom jumbotron featuring an SVG image at the top, some longer text that wraps early thanks to a responsive <code>.col-*</code> class, and a customized call to action.
                </p>
                <div class="d-inline-flex gap-2 mb-5">
                  <button class="d-inline-flex align-items-center btn btn-primary btn-lg px-4 rounded-pill" type="button">
                    Call to action
                    <svg class="bi ms-2" width="24" height="24"><use xlink:href="#arrow-right-short"></use></svg>
                  </button>
                  <button class="btn btn-outline-secondary btn-lg px-4 rounded-pill" type="button">
                    Secondary link
                  </button>
                </div>
              </div>
        
    </div>


    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>
</html>
html css twitter-bootstrap bootstrap-5
1个回答
0
投票

您需要添加一个 ccss 文件,其中包含以下行“min-width: 100%!重要!”以“覆盖”#outer 和 #inner div 的 bootstrap css

#outer{
    min-width: 100% !important;
    /* padding: 0 !important;
    margin: 0 !important; */
}

#inner{
    min-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}
<body>
    <div class="container my-5" id = "outer">
            <div class="p-5 text-center bg-body-tertiary rounded-3" id = "inner">
                <svg class="bi mt-4 mb-3" style="color: var(--bs-indigo);" width="100" height="100"><use xlink:href="#bootstrap"></use></svg>
                <h1 class="text-body-emphasis">Jumbotron with icon</h1>
                <p class="col-lg-8 mx-auto fs-5 text-muted">
                  This is a custom jumbotron featuring an SVG image at the top, some longer text that wraps early thanks to a responsive <code>.col-*</code> class, and a customized call to action.
                </p>
                <div class="d-inline-flex gap-2 mb-5">
                  <button class="d-inline-flex align-items-center btn btn-primary btn-lg px-4 rounded-pill" type="button">
                    Call to action
                    <svg class="bi ms-2" width="24" height="24"><use xlink:href="#arrow-right-short"></use></svg>
                  </button>
                  <button class="btn btn-outline-secondary btn-lg px-4 rounded-pill" type="button">
                    Secondary link
                  </button>
                </div>
              </div>
        
    </div>

© www.soinside.com 2019 - 2024. All rights reserved.