javascript - How to showhide elements using media query? - Stack Overflow

By using media query I would like to show the last element of the following list (2) when the screen wi

By using media query I would like to show the last element of the following list (2) when the screen width is above 768px.

Here is the jsfiddle like.
Here is the basic css code (1).


(1)

@media only screen and (min-width: 480px) {
    .menu li.hide{    
        visibility: none;
    }
}

@media only screen and (min-width: 768px) {
    .menu li.hide{    
        visibility: visible;
    }
}

(2)

<ul class="menu">
    <li>One</li>
    <li class='hide'>Nine</li>
</ul>​

By using media query I would like to show the last element of the following list (2) when the screen width is above 768px.

Here is the jsfiddle like.
Here is the basic css code (1).


(1)

@media only screen and (min-width: 480px) {
    .menu li.hide{    
        visibility: none;
    }
}

@media only screen and (min-width: 768px) {
    .menu li.hide{    
        visibility: visible;
    }
}

(2)

<ul class="menu">
    <li>One</li>
    <li class='hide'>Nine</li>
</ul>​
Share Improve this question edited Sep 20, 2012 at 17:48 nana 4,4911 gold badge37 silver badges49 bronze badges asked Sep 20, 2012 at 17:06 Lorraine BernardLorraine Bernard 13.5k23 gold badges85 silver badges138 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 1

Try this - DEMO

@media only screen and (max-width: 768px) {
    body{
        background:#030;
    }
    .menu li{    
        font:12px Verdana;    
        width:100px;
        padding-left:10px;
    }
    .menu li:last-child{    
        display: none
    }
}

@media only screen and (min-width: 769px) {
    body{
        background: honeydew;
    }
    .menu li{    
        font:22px Verdana;    
        width:200px;
        padding-left:20px;
    }
}

You can set the min and max width on the media query:

 @media screen and (min-width: 480px) and (max-width: 768px) {

I've updated your jsfiddle: http://jsfiddle/yyQ5u/28/

It looks like the main problem was with the order of things and the actual media queries. I put your non-conditional CSS at the top of the CSS pane and the media queries below.

Then I tweaked the media queries which seemed to sort of cover each other:

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

and

@media only screen and (min-width: 768px) {

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745485940a4629767.html

相关推荐

  • javascript - How to showhide elements using media query? - Stack Overflow

    By using media query I would like to show the last element of the following list (2) when the screen wi

    1小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信