Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Media query (max-width: 991px) not working at 991px

Tags:

css

frontend

I have following rule in my media.css file:

@media only screen and (max-width : 991px) {
    .menu nav { display: none; }
    .menu nav ul li {
        display: block;
        border-top: 1px solid #fff;
    }
}

It doesn't trigger at width 991px, however at 990px and lower it does. I tried to change value to 992px but it breaks my rules totally.

I use bootstrap 3.0 grid system in my html if it matters.

Full html:

<div class="menu">
    <div class="container">
        <div class="row">
            <div class="hidden-lg hidden-md col-sm-12 col-xs-12">
                <div id="touch-menu"><img src="img/menu_icon.png" alt="Меню"></div>
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <nav class="menu-nav">
                    <ul>
                        <li><a href="#">Главная</a></li>
                        <li><a href="#">О компании</a></li>
                        <li><a href="#">Вакансии</a></li>
                        <li><a href="#">Продукция</a></li>
                        <li><a href="#">Фотогалерея</a></li>
                        <li><a href="#">Новости</a></li>
                        <li><a href="#">Статьи</a></li>
                        <li><a href="#">Контакты</a></li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</div>

Full css:

.menu {
    position: fixed;
    top: 0;
    width: 100%;
    background-color: #01983b;
    background-image: url(../img/header_pattern.png);
    background-repeat: repeat;
    box-shadow: 0 3px 5px 0 rgba(0, 0, 0, 0.5),
    inset 0 -3px rgba(255, 255, 255, 0.2);
    overflow-x: hidden;
    min-height: 50px;
    z-index: 2;
}
#touch-menu {
    display: inline-block;
    float: right;
}
.menu nav ul {
    margin: 0;
    padding: 0;
    text-align: center;
}
.menu nav li {
    display: inline-block;
}
.menu nav ul li a {
    display: inline-block;
    position: relative;
    padding: 20px 15px;
    text-transform: uppercase;
    font-family: Arial, sans-serif;
    font-size: 14px;
    color: #fff;
}
.menu nav ul li a:hover {
    text-decoration: none;
}
@media only screen and (min-width : 992px) {
    .menu nav { display: block; }
}
@media only screen and (max-width : 991px) {
    .menu nav { display: none; }
    .menu nav ul li {
        display: block;
        border-top: 1px solid #fff;
    }
}

+js

$(document).ready(function() {
    var menu = $('.menu-nav');

    $('#touch-menu').on('click', function(e) {
        menu.slideToggle();
        return false;
    });

    $(window).resize(function() {
        if ( $(window).width() > 991 && menu.is(':hidden') ) {
            menu.removeAttr('style');
        }
    });
});
like image 259
Vyacheslav Kovalchuk Avatar asked Feb 13 '18 06:02

Vyacheslav Kovalchuk


1 Answers

I'd the same issue. I solved like that

@media only screen and (max-width : 991.5px) {

}

So your logic in 992px will not be breaked.

like image 148
Nurbol Sarsenbayev Avatar answered Nov 01 '22 05:11

Nurbol Sarsenbayev