html - 在移动 View 中使用 css 显示隐藏的 div

标签 html css responsive-design

这是我的 div 内容:

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

我默认使用内联样式隐藏它。现在我想要的是,仅在移动 View 中显示此 div。

我试过这样的:

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

但它没有显示 div,它仍然是隐藏的。如何使其仅在移动 View 中可见?

给我一​​些建议。

最佳答案

内联样式将覆盖样式表中的所有样式。我不推荐使用 !important,因为维护它可能是一场噩梦。

简单地取出你的内联样式:

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

然后将其放入您的样式表中:

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

关于html - 在移动 View 中使用 css 显示隐藏的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29116702/

相关文章:

html - Webkit/Blink 浏览器不遵守图例标签上的显示样式

javascript - 如何对齐文本以适应使用 Top : 50px; 向下移动的 Div

css - 当窗口大小调整时,div 内的图像也会调整大小 响应式设计

html - 使表格行的背景超出表格的边界

html - 在 IE 11 上使用字体 : it takes some tries to set the font

html - CSS 高度 : 100% not working on inline-block element although parent div has height

css - Angular 5 - 无法加载资源 : the server responded with a status of 404 (Not Found)

css - 是显示:table a perfectly acceptable method for equal height columns?

html - 响应式表单 'Submit' 按钮 - 移动版

html - css:内联 block div 的垂直对齐问题