如何从移动设备中排除 CSS

发布于 2024-10-31 21:19:57 字数 661 浏览 0 评论 0原文

我的网站主页上有一些 CSS 精灵。当您将鼠标悬停在元素上时,会出现不同的图像。

这在普通桌面上工作得很好,但是在移动设备(特别是 iPhone 或 iPad)上,悬停状态的元素显示在默认图像下方。

有没有办法我可以说,只在非桌面设备中应用悬停。

我正在查看媒体查询的 max-device-width 属性,但它并没有完全达到我想要的效果。例如:如果桌面浏览器调整窗口大小,悬停将不起作用怎么办?

<style media="screen">
#main{
 width: 985px;
 height: 1078px;
 background: url(../images/main.jpg);
 margin: 0px; 
 padding: 0;
 position: relative;
}

#main li {
 margin: 0; 
 padding: 0; 
 list-style: none;
}

#mainSection1 a { left: 642px; width: 193px; top: 282px; height: 18px; position: absolute; }
#mainSection1 a:hover { background: url(../images/main.jpg) -642px -1360px; }

</style>

I have some CSS sprites on the main page of my site. A different image appears when you hover over the element.

This works fine in a normal desktop, however on a mobile device (specifically an iPhone or iPad) the elements for the hover state appear stacked below the default image.

Is there a way I can say, only apply the hover in a non-desktop device.

I was looking over the max-device-width properties for the media queries, but it didn't exactly do what I wanted. Eg: What if a desktop browser resizes the window, then the hovers wont work.

<style media="screen">
#main{
 width: 985px;
 height: 1078px;
 background: url(../images/main.jpg);
 margin: 0px; 
 padding: 0;
 position: relative;
}

#main li {
 margin: 0; 
 padding: 0; 
 list-style: none;
}

#mainSection1 a { left: 642px; width: 193px; top: 282px; height: 18px; position: absolute; }
#mainSection1 a:hover { background: url(../images/main.jpg) -642px -1360px; }

</style>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青萝楚歌 2024-11-07 21:19:57

据我所知,浏览器窗口大小不应该触发受最大/最小设备宽度条件保护的CSS。不过,它会触发使用最大/最小宽度保护的 CSS。但是,您的屏幕分辨率可能会触发您的设备宽度部分。

但这不是您唯一的问题。 CSS 中的逻辑 px 单位并不总是映射到物理像素数。如果您在视口元标记中将初始比例设置为 1,则在 800x480 android 手机和 iphone4 上,事物可能看起来比应有的要大。

您可以在媒体查询中使用设备像素比来隔离这些设备。我认为 iphone4 的设备像素比是 2。

我知道以上内容本身都没有为您提供直接的解决方案,但您可以尝试将它们结合起来,找出适合您的解决方案。

As far as I know, the browser window size shouldn't trigger CSS guarded by conditions of max/min-device-width. It will trigger CSS guarded with max/min-width though. Your screen resolution, however, may trigger your device-width sections.

But that won't be your only issue. It's that the logical px unit in CSS doesn't always map to the physical pixel count. If you are setting the initial-scale to 1 in the viewport meta tag, on 800x480 android phones and iphone4 the things may look bigger than they ought to.

You can use device-pixel-ratio in your media query to isolate these devices. I think the iphone4 device-pixel-ratio is 2.

I know none of the above by themselves provide you with a direct solution, but you can try to combine them to find out what works for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文