SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2007
    Location
    Atlanta, GA
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Swapping stylesheets if on mobile browser

    Anyone know a way to swap a linked stylesheet in the header if someone has a mobile browser? I have googled and tried many methods but none seem to be working.

    FYI, this is a Wordpress site. I tried theme switching plugins but they didn't work well. I decided to try just switching stylesheets because that's all it needs. I have "style.css" and "style-mobile.css" that need to be swapped. Since WP required style.css would something mess up with style-mobile.css? Is there a better way to do this?

    I've tried :
    Code HTML4Strict:
    <link rel="stylesheet" type="text/css" media="screen" href="<?php bloginfo('stylesheet_url') ?>" />
    <link rel="stylesheet" type="text/css" media="only screen and (max-device-width: 1000px)" href="<?php bloginfo('stylesheet_directory'); ?>/style-mobile.css" />
    When I look on my iPhone it looks like it's loading both stylesheets.

    I tried a PHP script I found to detect browsers but that didn't work.

    Anyone know the best way to do this?

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2007
    Location
    Atlanta, GA
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I got this to work on my iPhone...

    Code HTML4Strict:
    <link rel="stylesheet" type="text/css" media="only screen and (min-device-width: 1000px)" href="<?php bloginfo('stylesheet_url') ?>" />
    	<link rel="stylesheet" type="text/css" media="print" href="<?php bloginfo('stylesheet_directory'); ?>/print.css" />
    	<link rel="stylesheet" type="text/css" media="only screen and (max-device-width: 1000px)" href="<?php bloginfo('stylesheet_directory'); ?>/style-mobile.css" />


    but...

    How can I include a link back to the original site?

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2007
    Location
    Atlanta, GA
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, that solution was a bad one too. It made the stylesheets not load at all in IE.

    There's got to be a standard usable solution for this!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •