简体   繁体   English

我不知道如何正确使用CSS文件中的媒体选择器来确定要为iPhone或iPad加载的图像

[英]I do not know how to use media selectors in my css file correctly to decide which image to load for iPhone or iPad

there are several html files to guide the user through our app and to introduce him to new features. 有几个html文件可以指导用户浏览我们的应用程序,并向用户介绍新功能。 It is a universal app for iPhone and iPad. 它是iPhone和iPad的通用应用程序。 If the user selects the help section for the iPhone version, i want to show him images scaled for the iPhone device. 如果用户选择iPhone版本的帮助部分,我想向他显示针对iPhone设备缩放的图像。

But now there is my problem. 但是现在有我的问题。 In the CSS file there is only one class boximage for all the images. 在CSS文件中,所有图像都只有一个class boximage。 How is it decided which image to load? 如何确定要加载哪个图像? Should i stuck each image in its own class? 我应该把每个图像都放在自己的班上吗?

Thanks in advance four your ideas! 在此先感谢您的四个想法!

Regards, buk 问候,北

You can try this. 你可以试试看

 <style type="text/css">
   @media all and (max-width: 800px) {
    .boximage{ background:url(image_name1.jpg)}
    }
    @media all and (min-width: 800px){ 
    .boximage{ background:url(image_name2.jpg)}
    }</style>

or Use javascript to find the user-agent and set the image from script. 或使用javascript查找用户代理并通过脚本设置图像。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM