0

This is my div content:

<div style="display:none;" id="sidebar">
<ul  class="nav navbar-inverse" style="list-style:none;">
<li><a href="#ccc">ccc</a></li>
<li><a href="#bbb">bbb</a></li>
</ul>
</div>

I hide it by default using the inline style. Now what I want is, to show this div only in mobile view.

I tried like this:

@media only screen and (max-width: 990px) {
        #sidebar { 
         display: block;
        }
      }

But it is not showing the div, it's still hidden. How do I make this visible only in the mobile view?

Give me some suggestions.

simanacci
  • 2,197
  • 3
  • 26
  • 35
aggy
  • 1
  • 1

3 Answers3

2

You can use !important to override a CSS rule but this is not so easy to maintain. :)

a stone arachnid
  • 1,272
  • 1
  • 15
  • 27
hornfl4kes
  • 120
  • 1
  • 10
2

The inline style will override any styles in your stylesheet. I wouldn't reccomend using !important, as it can be a nightmare to maintain.

Simply take out your inline style:

<div id="sidebar">
  <ul  class="nav navbar-inverse" style="list-style:none;">
    <li><a href="#ccc">ccc</a></li>
    <li><a href="#bbb">bbb</a></li>
  </ul>
</div>

Then put this in your stylesheet:

#sidebar { 
  display: none;
}
@media only screen and (max-width: 990px) {
  #sidebar { 
    display: block;
  }
}
Mike Hanslo
  • 274
  • 3
  • 14
0

Remove inline style from your content like so:

<header class="main-header">
  <div class="banner mobile_hide" role="banner">
    <img src="exemple_image_banner.jpeg" alt="Exemple Image Banner"/>
  </div>
</header>

Add this in your stylesheet:

/* --- Hidden viewport --- */
@media only screen and (max-width: 700px) {
    .mobile_hide { display:none; }
}
@media (min-width:701px) and (max-width:1199px) {
    .tablet_hide { display:none; }
}
@media only screen and (min-width: 1200px) {
    .desktop_hide { display:none; }
}