• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

PHP image show/hide on different media types

Question

Kalint    228

Is there a way to say, if desktop show this image but if mobile hide this image?

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0
threetonesun    1,204

Is there a way to say, if desktop show this image but if mobile hide this image?

 

Sure, give every image you want to hide the same class, use a media query to hide it when the screen resolution drops below a certain point.

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
ILikeTobacco    839

Is there a way to say, if desktop show this image but if mobile hide this image?

Yes, use CSS stylesheets. You can display a different stylesheet based on the platform

 

http://detectmobilebrowsers.com/

 

Don't know if those work but its the basic idea. Have two stylesheets. Show one with images if its desktop browser and another if mobile

Share this post


Link to post
Share on other sites
  • 0
+Human.Online    8,435

Screen resolution?  Use CSS and target towards mobiles.  Much more elegant!

Share this post


Link to post
Share on other sites
  • 0
threetonesun    1,204

Screen resolution?  Use CSS and target towards mobiles.  Much more elegant!

 

Eh? Based on what. Media queries are CSS. You can get more specific with orientation and device ratio, if you want, but in the end resolution will get you where you need to be.

 

For reference, here's a very detailed guide to targeting every Apple i-device with media queries:

http://www.stephentgilbert.com/mediaqueries/

 

Goes slightly overboard, depending on the situation. For a very simple optimization, you might just want a killswitch on some images when the screen size is < 1024px.

Share this post


Link to post
Share on other sites
  • 0
+Human.Online    8,435

Sorry pal, am half asleep, I read "query" as "jQuery"

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
ILikeTobacco    839

I suppose the next question is, what is the reasoning. If the purpose is to save bandwidth for mobile devices, the resolution of newer devices would now result in wasting bandwidth.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.