简体   繁体   English

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

[英]How to use media query for max-width: 767px using Bootstrap 4 mobile first

I am converting a website that I made from scratch to be responsive using Bootstrap 4. I started the conversion before I realized that Bootstrap 4 is mobile first, my site was developed desktop first. 我正在使用Bootstrap 4将我从头创建的网站转换为可响应的网站。在我意识到Bootstrap 4首先是移动设备,我的网站首先是桌面开发之前,我开始了转换。 Without going back and re-doing the entire site, I thought I could just add a few changes with this media query: 不用回头再做整个站点,我想我可以使用此媒体查询添加一些更改:

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

The changes are not shown on the site but I can see the code when I inspect element and click on sources. 所做的更改未显示在网站上,但是当我检查元素并单击源时,我可以看到代码。 My other queries are working just fine, they look like this: 我的其他查询工作正常,看起来像这样:

    @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;
        }
    }

I tried adding this meta tag: 我尝试添加此元标记:

    <meta name="viewport" content="width=device-width, initial-scale=1, 
    maximum-scale=1">

That made everything look jumbled beneath 767px. 这使得所有内容在767px以下都显得混乱不堪。

I just need to make a few minor tweaks for when the screen is less than 767px and I do not want to re-build my site from mobile first, nor do I want to convert to Bootstrap 3 at this point. 当屏幕小于767px时,我只需要进行一些小调整,并且我不想从移动设备重新构建网站,也不想在此时转换为Bootstrap 3。 Please Help! 请帮忙!

If you are using safari browser use viewport as <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> Safari Documentation 如果您使用的是Safari浏览器,请使用视口作为<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no"> Safari文档

and another reference why shrink-to-fit=no 和另一个参考, 为什么缩小到适合=否

As per Bootstrap 4 documentation Responsive breakpoints are 根据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) { ... }

other direction 其他方向

// 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

and minimum and maximum breakpoint widths 最小和最大断点宽度

// 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) { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM