首页 > 解决方案 > Bootstrap 4. 为什么不在移动设备上使用全宽?

问题描述

好的,所以我准备好被这个问题一笑了之,因为我认为我遗漏了一些非常明显的东西,但我很累,今天是星期六,我宁愿不工作。

我只是将一个项目从 Bootstrap 3 移动到 Bootstrap 4。谁能告诉我为什么以下代码不会在移动(xs)设备上全屏显示?

这是相当标准的BS4

<html>
<head>
    <!-- CSS only -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"/>

        <!-- JS, Popper.js, and jQuery -->
        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
        <!-- JS, Popper.js, and jQuery -->

</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col">
                This is a test
            </div>
            <div class="col">
                This is a test  
            </div>
        </div>
    </div>
</body>

如图所示,我的左侧和右侧都有排水沟.container

谷歌浏览器开发者工具移动预览

根据文档,这应该是开箱即用的。我究竟做错了什么?

标签: twitter-bootstrapbootstrap-4

解决方案


将 container-fluid 用于全屏容器

<html>
<head>
    <!-- CSS only -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"/>

        <!-- JS, Popper.js, and jQuery -->
        <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
        <!-- JS, Popper.js, and jQuery -->

</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col">
                This is a test
            </div>
            <div class="col">
                This is a test  
            </div>
        </div>
    </div>
</body>

推荐阅读