如何使用媒体查询最大宽度:767px 使用 Bootstrap 4 移动优先

Mel*_*vin 1 html css media-queries twitter-bootstrap bootstrap-4

我正在将一个从头开始制作的网站转换为使用 Bootstrap 4 的响应式网站。在我意识到 Bootstrap 4 是移动优先的,我的网站是桌面优先开发的之前,我就开始了转换。无需返回并重新制作整个网站,我想我可以使用此媒体查询添加一些更改:

    @media only screen and (max-width: 767px) {
        /***HOMEPAGE - HEADER***/
        #header {
            height: 45vh;
            background-attachment: inherit;
        }
    }
Run Code Online (Sandbox Code Playgroud)

这些更改未显示在网站上,但当我检查元素并单击源时,我可以看到代码。我的其他查询工作正常,它们看起来像这样:

    @media (min-width: 768px) and (max-width: 991px) {
        /***BODY ***/
        html,
        body,
        a,
        blockquote {
            font-size: 18px;
        }

        /***MAIN & MOBILE NAV***/
        .main-nav {
            display: none;
        }

        #nav-icon3 {
            display: block;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我尝试添加这个元标记:

    <meta name="viewport" content="width=device-width, initial-scale=1, 
    maximum-scale=1">
Run Code Online (Sandbox Code Playgroud)

这使得 767 像素下的所有内容看起来都很混乱。

当屏幕小于 767px 时,我只需要进行一些小的调整,并且我不想首先从移动设备重新构建我的网站,此时我也不想转换为 Bootstrap 3。请帮忙!

Zna*_*war 5

如果您使用 Safari 浏览器,请使用视口作为 <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> Safari 文档

另一个参考为什么shrink-to-fit=no

根据Bootstrap 4 文档响应断点是

// Extra small devices (portrait phones, less than 576px)
// No media query since this is the default in Bootstrap

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }

// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }

// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }
Run Code Online (Sandbox Code Playgroud)

其他方向

// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px) { ... }

// Small devices (landscape phones, less than 768px)
@media (max-width: 767px) { ... }

// Medium devices (tablets, less than 992px)
@media (max-width: 991px) { ... }

// Large devices (desktops, less than 1200px)
@media (max-width: 1199px) { ... }

// Extra large devices (large desktops)
// No media query since the extra-large breakpoint has no upper bound on its width
Run Code Online (Sandbox Code Playgroud)

以及最小和最大断点宽度

// Extra small devices (portrait phones, less than 576px)
@media (max-width: 575px) { ... }

// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) and (max-width: 767px) { ... }

// Medium devices (tablets, 768px and up)
@media (min-width: 768px) and (max-width: 991px) { ... }

// Large devices (desktops, 992px and up)
@media (min-width: 992px) and (max-width: 1199px) { ... }

// Extra large devices (large desktops, 1200px and up)
@media (min-width: 1200px) { ... }
Run Code Online (Sandbox Code Playgroud)