css - 在现有的 css 文件中添加 .hidden-phone 以隐藏背景图像

标签 css twitter-bootstrap responsive-design

我相信这个问题有一个简单的答案...

使用 Twitter Bootstrap,我在我的 style.css.erb 文件中有这个:

.login_page body {height:100%;
        max-width:inherit;
        margin:0 20px;
        background-image: url(<%= image_path 'oap_dotlogo.png' %>);
        background-repeat: no-repeat;
            background-position: 5%, 80%;
        background-color: #E3F5FD;
    }

这太棒了,除了在手机上,背景 Logo 让人头疼。我想把那个标志放在手机上。

我看到 bootstrap-responsive.css 已经定义了 .hidden-phone:

@media (max-width: 767px) {
  .hidden-desktop {
    display: inherit !important;
  }
  .visible-desktop {
    display: none !important;
  }
  .visible-phone {
    display: inherit !important;
  }
  .hidden-phone {
    display: none !important;
  }
}

那么,我该如何修改 style.css.erb 以便 background-image 标签具有 .hidden-phone 类?

我已经尝试了一些在 style.css.erb 中添加 .hidden-phone 的排列组合,但似乎没有任何效果 - 我一定是语法错误。

谢谢! 戴夫

最佳答案

听起来您在这里混淆了 CSS 和 HTML。当你说:

[H]ow do I modify the style.css.erb so that the background-image tag has the .hidden-phone class?

...您不能将类添加到 CSS 声明中。您实际上并不想隐藏您的元素(在这种情况下是body),而是在小屏幕尺寸下您想要修改背景属性(property)。因此,在您已有的媒体查询中,添加以下内容:

@media (max-width: 767px) {
  .login_page body { background-image: none; }
  ...
  all your other small-screen styles
}

然后,默认将显示您的 background-image 并且您正在为小屏幕删除它。如果图像很大,您可能会考虑移动设备优先的方法。即做相反的事情,正如 @po228 提到的那样——只为更大的视口(viewport)宽度添加 background-image

关于css - 在现有的 css 文件中添加 .hidden-phone 以隐藏背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15413596/

相关文章:

css - React-selectize 无法加载 css

css - 如何让 Bootstrap 将缩略图放入 2 列而不是 800 x 600 及以下的 1 列?

html - 如何以响应方式显示适用于桌面和移动纵向和横向的图形?

html - 使用组件函数设置 HTML 对象的样式

css 和媒体查询不起作用 - MQ 新手

javascript - 如何根据屏幕尺寸更改 slider 和表单高度

javascript - 如何关闭其他子菜单并在菜单中搜索?

jquery - 响应式图像上的 Logo 放置

javascript - 如何将第 n 到第 n 个元素包装在 div 中

javascript - jQuery 突出显示不适用于 Bootstrap v4 按钮