简体   繁体   English

在CSS中为移动视图修改/禁用jQuery代码

[英]Adapt/disable jQuery code for mobile view in css

I have sticky header in my website. 我的网站上有标头 When I tried to optimize my header for mobile, everything was ok but, when it became sticky it resize him or something like that so my navigation is not visible. 当我尝试针对移动设备优化标题时,一切都还不错,但是当它变得发时,它会调整其大小或类似内容,因此导航不可见。 I want to know is there any way to change jQuery code in css so my header doesn't resize when it became sticky . 我想知道有什么方法可以更改css中的jQuery代码,以使我的标头在变得粘滞时不会调整大小。

Here is my code example: 这是我的代码示例: http://codepen.io/anon/pen/JKXYpa http://codepen.io/anon/pen/JKXYpa

Note: If you want to see where is the problem, just resize your browser on width < 480px. 注意:如果要查看问题出在哪里,只需将浏览器的大小调整为<​​480px。

The following CSS should work for you. 以下CSS应该适合您。 You're doing a few things that are causing problems. 您正在做一些导致问题的事情。 Most importantly, your #wrapper declaration contradicts itself. 最重要的是,您的#wrapper声明与自己矛盾。 You have declared a min-width that is larger than your max-width. 您声明的最小宽度大于最大宽度。 min-width has to be less than max-width. 最小宽度必须小于最大宽度。

I've made a few other small adjustments including reducing the header font sizes in your media query for small screen sizes, to make the nav fit. 我进行了一些其他小的调整,包括在较小的屏幕尺寸的媒体查询中减小标题字体的尺寸,以使导航更合适。 Otherwise, it will wrap below the blue container. 否则,它将包裹在蓝色容器下方。

    *{
        padding:0;
        margin:0;
    }

    /* Header */
    #header {
        transform: translateZ(10px);
        background-repeat: no-repeat;
        background-color:#3cb5f9;
        width: 100%;
        height: 80px;
        top:200;
        left: 0;
        z-index: 999;
        box-sizing:border-box;
        border-bottom:1px solid white;
    }
    #header nav {
        display: inline-block;
        float:right;
        line-height:80px;
    }
    #header nav a {
        margin-left: 25px;
        color: #fafafa;
        font-weight: 700;
        font-size: 18px;
        text-decoration:none;
        -webkit-transition: all 0.5s;
        -moz-transition: all 0.5s;
        -ms-transition: all 0.5s;
        -o-transition: all 0.5s;
        transition: all 0.5s;
    }
    #header nav a:hover {
        color: black; 
    }
    #header img {
        line-height:80px;
        margin-top:14px;
        display:block;
        float:left;
        height:51px;
    }

    .clearfix{
        display: block;
        width:70%;
        clear:both;
        margin: 0 auto;
    }

    /*Mobile part*/
    @media screen and (max-width: 480px) {

        #header {
            width: 100vw;
            float:none;
        }

        p{ 
            font-size: 0.5em;
        }

        ::-webkit-scrollbar{
            display:none;
        } 

        #header nav{
            float:right;
        }
        #header nav {
            display: inline-block;
            float:center;
            line-height:80px;
        }
        #header nav a {
            font-size: 12px;
            margin-left: 10px;
        }
        #header nav a:hover {
            color: black; 
        }
        #header .clearfix {
            width: 95%;
        }
    }

    /* Other */

    #main{
        width: 100%;
        color:#3cb5f9;
        margin: 0 auto; 
    }

    .container{
        width:70%;
        margin: 0 auto;
    }

    #wrapper {
        max-width:1240px;
        height:2000px;
        color:#3cb5f9;
        margin: 0 auto; 
    }

    .home{
        width:100vw;
        height:600px;
        clear:both; 
    }

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

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