简体   繁体   English

iPad设备的CSS值是否不同?

[英]Different CSS values for iPad devices?

I have simple HTML5 game and I would like to set different CSS values for selectors if the game is running on iPad. 我有一个简单的HTML5游戏,如果该游戏在iPad上运行,我想为选择器设置不同的CSS值。

For example: 例如:

Normal value for all devices (without iPad): 所有设备(没有iPad)的正常值:

#playIcon {
    position: absolute;
    color: white;
    z-index: 10;
    top: 15vw;
    left: 33%;
}

and for iPad device should be value: 对于iPad设备应该是有价值的:

top: 20vw;

How can I do this in simple and effective way? 我如何以简单有效的方式做到这一点?

Media query for iPad in landscape and portrait : iPad的横向和纵向媒体查询:

@media only screen and (min-device-width : 768px) and (max-device-width : 1024px)

only landscape, add : 仅风景,添加:

and (orientation : landscape)

only portrait, add : 仅纵向,添加:

and (orientation : portrait)

If you don't want to use media queries because you want to target iPad only, you can use this script (source : Detect iPad users using jQuery? ) : 如果您不想因为只想定位iPad而使用媒体查询,则可以使用以下脚本(来源: 使用jQuery检测iPad用户? ):

var isiPad = navigator.userAgent.match(/iPad/i) != null;

And for example (JS): 例如(JS):

if(isiPad) {
  var playIcon = document.getElementById('playIcon');
  playIcon.className = "ipad";
}

(CSS): (CSS):

#playIcon.ipad {
   top: 20vw;
}

I haven't tested the js way, so I hope there is no mistake ... 我还没有测试过js方式,所以我希望没有错误...

Don't think you can achieve iPad detection with css. 不要以为您可以使用CSS实现iPad检测。 With Javascript it's possible to check the user agent. 使用Javascript,可以检查用户代理。

var isIpad = (navigator.userAgent.match(/iPad/i) != null);

If you want to target iPads only by css, the closest you can get is probably by using 如果您只想通过CSS定位iPad,则可以使用来获取最接近的iPad

@media only screen and (-webkit-min-device-pixel-ratio: 1) {}

This will also apply to any device with more dense pixels (like retina displays), which are a lot of devices. 这也适用于像素较多的任何设备(例如视网膜显示器),这些设备很多。 You can also add iPad display width and height to target it more precisely but there's no sureshot for targeting only iPads just with css. 您还可以添加iPad的显示宽度和高度,以更精确地定位它,但是对于仅使用CSS定位iPad的人来说,没有把握。

Anyway, well designed product should be ok with non-specific styling, just using media queries for different viewports. 无论如何,只要使用针对不同视口的媒体查询,设计良好的产品应该可以使用非特定的样式。 Seeing what you are trying to do I assume you are trying to cope with some sort of iPad specific toolbar. 看到您要执行的操作,我认为您正在尝试处理某种iPad专用工具栏。 These issues are tricky because you cannot be sure that with the next version of iOS you won't have to restyle it again. 这些问题很棘手,因为您不确定使用下一版iOS时不必重新设置其样式。 So if possible, try to solve this a way you won't have to cope with specific devices... 因此,如果可能的话,请尝试解决此问题,而不必使用特定设备...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 适用于不同设备的不同版本的应用程序 - iPhone 到 iPad - Different versions of app for different devices - iPhone to iPad 使用自适应布局的iPhone和iPad设备的不同uitableview单元高度 - Different uitableview cell height for iPhone and iPad devices using adaptive layout CSS-移动按钮出现在不同区域,不同设备中 - CSS - Mobile button appears in different areas, different devices iOS设备(iPhone / iPad)上的CSS3过渡:应用不透明过渡DOM对象浮华 - CSS3 transition on iOS devices (iPhone / iPad): applying opacity transition the DOM object flashy 对于不同的iPhone设备,CLLocation为CLLocationSpeed返回不同的值 - CLLocation returns different values for CLLocationSpeed for different iPhone devices 如何在各种设备上使字体大小看起来不错? UIWebView中iPad和iPhone的不同视口 - How can I make my font size look good on various devices? Different viewport for iPad and iPhone in UIWebView iPad和iPad 2呈现CSS的方式不同? - iPad & iPad 2 rendering CSS differently? 为受限设备部署ipad应用 - Deploy ipad app for limited devices MutliTouch可在iPad Simulator上运行,但不能在设备上运行 - MutliTouch Works on iPad Simulator, but not devices 不同设备尺寸的iOS自动布局约束值 - iOS Auto Layout constraints values for different devices sizes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM