问题
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