问题
I made an announcement div and I want it to disappear when I use the mobile version of the webpage because it occupy to much space when resized for the mobile version. How can I hide a div when the size of the webpage becomes bigger?
for example: mobile web surfing
my code is
body {margin:0;}
.icon-bar {
width: 100%;
background-color: #0088B8;
overflow: auto;
}
.icon-bar a {
float: left;
width: 20%;
text-align: center;
padding: 12px 0;
transition: all 0.3s ease;
color: white;
font-size: 36px;
}
.icon-bar a:hover {
background-color: #0073C4;
}
.active {
background-color: #9b0a0a !important;
}
<div class="icon-bar">
<a href="./index.php"><i class="fa fa-home"></i></a>
<a href="./search.php"><i class="fa fa-search"></i></a>
<a href="./news.php"><i class="fa fa-envelope"></i></a>
<a href="./search.php?search_id=unanswered"><i class="fa fa-globe"></i></a>
<a href="#"><i class="fa fa-trash"></i></a>
</div>
回答1:
Maybe he is new to html and css... Try to use css rules to achieve this, like Robert said media queries. Put in your html head this line:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
And in your css file wirte below your div-rules (lets say your div has the id="test"):
@media only screen and (min-width: 800px) {
#test {
display: none;
}
}
Now the div is hidden when the screen width is larger than e.g. 800px.
来源:https://stackoverflow.com/questions/44610649/how-to-hide-div-when-mobile