Angel
Angel

Reputation: 33

Media Queries Conflict

I am using media queries to modify my css on different devices, however, when I make the changes to the second media query (max-width: 767) it overrides the css for mobile. Anyone have any idea why that might be?

Here's the css:

/* Mobile */

@media only screen and (min-width: 320px) and (max-width: 480px) {
  /* Style adjustments for viewports 480px and under go here */
    .row {
        text-align: center !important;
        margin-left: auto !important;
        margin-right: auto !important;
        width: 98% !important;
        padding-left: 1% !important;
        padding-right: 1% !important;
    }

    span {
        letter-spacing: 20px !important;
    }

    .nav li {
        margin-right: 22px !important;
        text-align: center !important;
        letter-spacing: 2px !important;
    }

    ul li:last-child { 
        margin-right: 0px !important; 
    }

    .intro h1 {
        font-size: 44px !important;
        margin-bottom: -40px !important;
    }

    .intro img {
        visibility: hidden !important;
    }

    .dotted_line {
        visibility: hidden !important;
    }

    .cta {
        height: 450px !important;
        width: 330px !important;
        margin-top: -30px !important;
        margin-bottom: -250px !important;
    }

    .cta h2 {
        font-size: 20px !important;
        margin-left: 5px !important;
        margin-top: -10px !important;
    }

    .cta p {
        font-size: 16px !important;
        margin-left: 5px !important;
        margin-top: -10px !important;
    }

    .home_form {
        margin-left: 20px !important;
    }

    .left input {
        width: 280px !important;
        margin-bottom: 10px !important;
    }

    .right {
        width: 280px !important;
        float: none !important;
    }

    .right textarea {
        height: 120px !important;
        width: 285px !important;
    }

    .submit {
        background: url('../img/submit_btn.png') no-repeat !important;
        float: left !important;
        margin-top: 20px !important;
    }

    .social {
        visibility: hidden !important;
    }

    .social_icons {
        margin-right: auto;
        margin-left: auto;
    }

    footer .left p {
        width: 330px !important;
    }

    footer .middle {
        visibility: hidden;
    }

    footer .right {
        visibility: hidden;
    }

    .copyright {
        margin-left: 10px !important;
        margin-bottom: -40px;
    }
}

@media only screen and (max-width: 767px) {
    body { -webkit-text-size-adjust: none; -ms-text-size-adjust: none; width: 100%; min-width: 0; margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }

    .container { min-width: 0; margin-left: 0px; margin-right: 0px; }
    .row { width: 100%; min-width: 0; margin-left: 0; margin-right: 0; }
    .row .row .column, .row .row .columns { padding: 0; }
    .column, .columns { width: auto !important; float: none; margin-left: 0; margin-right: 0; }
    .column:last-child, .columns:last-child { margin-right: 0; float: none; }
    .row .row .column, .row .row .columns { padding: 0; }
    .column, .columns { width: auto !important; float: none; margin-left: 0px; margin-right: 0px; }
    .column:last-child, .columns:last-child { margin-right: 0; float: none; }
    [class*="column"] + [class*="column"]:last-child { float: none; }
    [class*="column"]:before, [class*="column"]:after { display: table; }
    [class*="column"]:after { clear: both; }


    .push_one, .push_two, .push_three, .push_four, .push_five, .push_six, .push_seven, .push_eight, .push_nine, .push_ten, .push_eleven, .centered { margin-left: 0% !important; }

    span {
        letter-spacing: 40px !important;
    }

    .nav li {
        margin-right: 62px !important;
        text-align: center !important;
        letter-spacing: 6px !important;
    }

    ul li:last-child { 
        margin-right: 0px !important; 
    }

    .intro h1 {
        font-size: 44px !important;
        margin-bottom: -40px !important;
    }

    .intro img {
        visibility: hidden !important;
    }

    .dotted_line {
        visibility: hidden !important;
    }

    .cta {
        height: 450px !important;
        width: 330px !important;
        margin-top: -30px !important;
        margin-bottom: -250px !important;
    }

    .cta h2 {
        font-size: 20px !important;
        margin-left: 5px !important;
        margin-top: -10px !important;
    }

    .cta p {
        font-size: 16px !important;
        margin-left: 5px !important;
        margin-top: -10px !important;
    }

    .home_form {
        margin-left: 20px !important;
    }

    .left input {
        width: 280px !important;
        margin-bottom: 10px !important;
    }

    .right {
        width: 280px !important;
        float: none !important;
    }

    .right textarea {
        height: 120px !important;
        width: 285px !important;
    }

    .submit {
        background: url('../img/submit_btn.png') no-repeat !important;
        float: left !important;
        margin-top: 20px !important;
    }

    .social {
        visibility: hidden !important;
    }

    .social_icons {
        margin-right: auto;
        margin-left: auto;
    }

    footer .left p {
        width: 330px !important;
    }

    footer .middle {
        visibility: hidden;
    }

    footer .right {
        visibility: hidden;
    }

    .copyright {
        margin-left: 10px !important;
        margin-bottom: -40px;
    }

}

I haven't made many adjustments to the second media query other than the span and the .nav li but that was enough to see the problem in the header & nav.

Upvotes: 1

Views: 4545

Answers (2)

Mike Brant
Mike Brant

Reputation: 71422

Yes, you probably need a min-width in your second media query as ALL devices that meet the criteria of the first media query, will automatically meet the criteria of the second.

Upvotes: 0

Linus Caldwell
Linus Caldwell

Reputation: 11078

Because @media only screen and (max-width: 767px) also addresses devices with a screen width of 320px <= x <= 480px. You need to set a min-width: 481px here.

Upvotes: 3

Related Questions