css - 仅在台式机和笔记本电脑上隐藏图标的媒体查询

标签 css media-queries

我的网页标题中有一个可点击的图标图像;当页面在台式机、笔记本电脑和/或任何更大的屏幕上拉出时,我想隐藏图标图像。但是,我希望在移动设备/手机和手持平板电脑上拉起页面时显示该图标。

这是我尝试过的:

@media screen and (min-width: 0px) and (max-width: 700px) {
  .ghost {
    margin-left: 500px;
    /*show the icon on smaller screen*/
  }
}

@media screen and (min-width: 701px) and (max-width: 1024px) {
  .ghost {
    margin-left: 500px;
    display: none;
    /*hide the icon on larger screens*/
    visibility: hidden;
  }
}

/* Adding this so the demo is visible even though the image link is broken. --editor */
.ghost img { border: 1px solid blue; }
<div style="cursor:pointer;" onclick="openNav()" class="ghost"><img src="img/ic_ghost.svg" alt="ghost" /></div>

...请问我能得到一些帮助吗? ...谢谢

最佳答案

你好

如果您只想在 <= 700px 的设备上显示图标,您的代码应如下所示。在第一个@media 中设置min-width: 0px,在第二个@media 中设置max-width: 1024px 是不必要的。

@media screen and (max-width: 700px) {
    .ghost {
        margin-left: 500px;

    }
}

@media screen and (min-width: 701px) {

    .ghost {
        margin-left: 500px;
        display: none; /* Acts like this item isn't there at all */
        visibility: hidden; /* Doesn't show the item, but saves space for it */
    }
}

我不知道你的全部问题,但如果你想在大屏幕上表现得好像它不存在,下面的 CSS 会更好;)

.ghost {
    display: none;
}

@media screen and (max-width: 700px) {

    .ghost {
        margin-left: 500px;
        display: initial;
    }
}

您可以找到有关媒体查询的更多信息,例如关于这个W3Schools site .

干杯

关于css - 仅在台式机和笔记本电脑上隐藏图标的媒体查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49226461/

相关文章:

css - 多列在使用 ASP.NET 的 IE11 中不起作用

需要纯 CSS 菜单帮助

css - 是否可以针对相同的 CSS 规则组合媒体查询?

css - 只有一个 css 媒体查询会影响元素的样式(只发生在 Chrome,而不是 Firefox)

css - 为什么 @media 查询不起作用?

html - 如何根据 Bootstrap 3 中的屏幕大小以不同的顺序显示 div?

html - 在div之间添加一个空白

CSS百分比宽度和高度以及分辨率问题

jquery - Chrome 中媒体查询最大宽度以错误的宽度启动

html - 用于在 iPhone 4 和 iPhone 5 大小的屏幕上定位横向的 CSS3 媒体查询