Mobile Optimized CSS: Using a default CSS for desktop browsing and another for mobile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Angel88
    New Member
    • Mar 2013
    • 3

    Mobile Optimized CSS: Using a default CSS for desktop browsing and another for mobile

    Hi. I'm Angel.

    Just recently I've received a project which is about a mobile-optimized web page. The client asked me to create two CSS files one is designed for default browsing using a desktop computer, while the other would is designed for mobile browsing.

    I had no problem with the default CSS, but there's some difficulty with the second one. Especially when the banner is concerned. In the default stylesheet, the banner should be on its original size which is 400x200 but if the user browse the page using his/her phone, say, iPhone, the banner should display another banner which has the size of 400x100. I've tried to use the div: display:none function but it seems to have no effect at all. The page still displays the original banner, eventhough both are uploaded into the same folder.
    I'm wondering if how could I make this thing possible. I have tried different solutions, but still nothing happens. Do you guys have any idea? Please I need your help to solve this mystery.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's hard to say where you went wrong without the code. We don't need to see all of it, just the HTML and CSS that relates to the banner you're talking about.

    Comment

    • Angel88
      New Member
      • Mar 2013
      • 3

      #3
      Sorry about that...

      Here's the code for html:

      Code:
      <?php
      if(strpos($_SERVER['HTTP_USER_AGENT'], "iPhone"))
      {
          ?><link rel="stylesheet" href="mock.css" type="text/css" media="handheld" /><?php
      }
      else
      {
          ?><link rel="stylesheet" href="style.css" type="text/css" media="screen" /><?php
      }
      ?>
      
      <html>
      <head>>
      <body>
      <div class="header"><img src="images/banner.png" alt="" /></div>
      </body>
      </head>
      </html>
      
      *As you can see I used php code to call the proper stylesheet for both desktop and mobile device.
      Here's the code for CSS:

      Code:
      @media (max-width: 520px){
      /*Banner*/
      .bannerpic { background-image:url(images/banner2.png)padding:14px 0 0 16px}
      }
      
      I suspect that there's something wrong with the bannerpic code. But the banner must be displayed on that exact position.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You don't have an element with the bannerpic class that you reference in your css.

        Comment

        • Angel88
          New Member
          • Mar 2013
          • 3

          #5
          Bet I have...

          Code:
          img {border:0;vertical-align:top;text-align:left}
          #header .row-1 .bannerpic { background-image:url(images/banner2.png); padding:14px 0 0 16px}
          *Alignment*
          .bannerpic {float:none; overflow:hidden; padding: 0 auto}
          All these are partial codes of the second CSS.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            I know you have the CSS. I'm saying you don't have the HTML element that references that class.

            Comment

            Working...