admin管理员组文章数量:1426782
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
3 Answers
Reset to default 1Try 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) {
本文标签: javascriptHow to showhide elements using media queryStack Overflow
版权声明:本文标题:javascript - How to showhide elements using media query? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745485939a2660383.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论