css - 响应式设计 css3 在小屏幕上显示而不是在大屏幕上显示

标签 css media-queries responsive-design

css3 媒体查询和响应式设计的新手。

我想知道如何只在小屏幕上而不是在大屏幕上显示某些东西(比如 div)。 我试过类似的东西:

@media (max-width: 480px) {
.show-on-small-only{ display:block; visibility:visible;}
}

... 任何更大的东西都有例如:

@media (max-width: 768px) {
.show-on-small-only{ display:hidden; visibility:none;}
}

它似乎没有按预期工作。

可能值得指出我正在使用 bootstrap 2.0

最佳答案

更好的做法是让所有默认样式都适合移动设备,然后使用 min- 媒体查询来调整大小:

div { /*put whatever your default styles are first*/ }

/* Then use the media query to hide it at 481 and wider */
@media all and (min-width:481px) {
    div { display:none }
}

320andupSkeletonthis page 的 CSS举些例子。查看 this CSS 底部的辅助类对于不可见/隐藏等之间的差异

关于css - 响应式设计 css3 在小屏幕上显示而不是在大屏幕上显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9523434/

相关文章:

html - 以边距居中

html - 移动/桌面媒体查询不适用于手机

html - 在移动屏幕中垂直对齐 li 元素

css - jquery 获取 div 的媒体查询宽度值(而不是我的 css 正常值)并在函数中使用它

css - 你能帮我做移动媒体查询吗?

css - Bootstrap 4 模态未显示

css - 根据变量突出显示表格行

javascript - :first-child and :last-child not working in owl carousel 2

css - @font-face 不适用于 github 页面

html - 媒体查询不接受另一个