Display: none - Show on the mobile, but not on the desktop

a 夏天 提交于 2019-12-11 09:35:39

问题


I am attempting to use display: none so an element will show up on a smaller resolution (or a mobile device) but not on the main css for larger screen sizes.

I think it is probably logical that it doesn't show but I can't figure out a way to get around this.

footer {
    display: none;
}

@media handheld and (max-width:480px),
screen and (max-device-width: 480px),
screen and (max-width: 600px)
{
  footer {
    background-color: #colour;
    position:fixed;
    bottom: 0;
    left: 0;
    right: 0;
  }
}

回答1:


You can set it to display:block within your media query, this will override the display:none;

Another method would be a jQuery/Javascript solution, potentially something like this: Notes: This is using the jQuery library which is nice to work with for things such as this, as it easily helps with browser comptability and ease of use.

<script type="text/javascript">
$(document).ready(function (){
    if( navigator.userAgent.match(/Android/i) ||
     navigator.userAgent.match(/webOS/i) ||
     navigator.userAgent.match(/iPhone/i) ||
     navigator.userAgent.match(/iPod/i) ||
     navigator.userAgent.match(/BlackBerry/)
     ){
    $(.footer).css("display:none")  
    } else {

        $('.footer').css("display:block")
        });
    }
});
</script>


来源:https://stackoverflow.com/questions/11996925/display-none-show-on-the-mobile-but-not-on-the-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!