Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Change style based on device type

Change style based on device type

Scheduled Pinned Locked Moved Web Development
questioncsharpjavascripthtmlcss
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mundo Cani
    wrote on last edited by
    #1

    Hello, I'm new to the web development world and I'm hoping someone can point me in the right direction. I have an asp.net website (I'm using a starterkit from www.asp.net). I want to apply a different stylesheet if the client is a mobile device. I'm using a plugin that gives me the client device's display settings. If the display is below a certain resolution I want to use mobile.css. Otherwise, I want to use default.css. My understanding is that the style gets applied on the server when a request is made, and the resulting html is returned to the client. But I want the decission as to what style gets applied to be made by the client. How can I go about using javascript to change the stylesheet on the fly? Or, if I'm barking up the wrong tree, is there a way for me to program this functionality in the codebehind (I don't think there is, as the decission would have to be made on the client...)? Thanks for your help! (I'm a total noob in this area!)

    Ian

    S J J 3 Replies Last reply
    0
    • M Mundo Cani

      Hello, I'm new to the web development world and I'm hoping someone can point me in the right direction. I have an asp.net website (I'm using a starterkit from www.asp.net). I want to apply a different stylesheet if the client is a mobile device. I'm using a plugin that gives me the client device's display settings. If the display is below a certain resolution I want to use mobile.css. Otherwise, I want to use default.css. My understanding is that the style gets applied on the server when a request is made, and the resulting html is returned to the client. But I want the decission as to what style gets applied to be made by the client. How can I go about using javascript to change the stylesheet on the fly? Or, if I'm barking up the wrong tree, is there a way for me to program this functionality in the codebehind (I don't think there is, as the decission would have to be made on the client...)? Thanks for your help! (I'm a total noob in this area!)

      Ian

      S Offline
      S Offline
      subrata jana
      wrote on last edited by
      #2

      u can do it in ur client script by adding dynamic CSS and removing old one. And also donot cache the css in client side. use CacheControl=no-cache for that CSS probaly in IIS as a header.

      M 1 Reply Last reply
      0
      • S subrata jana

        u can do it in ur client script by adding dynamic CSS and removing old one. And also donot cache the css in client side. use CacheControl=no-cache for that CSS probaly in IIS as a header.

        M Offline
        M Offline
        Mundo Cani
        wrote on last edited by
        #3

        Does the CSS need to be embedded in the HTML? Or can it just be linked to CSS on the server?

        Ian

        1 Reply Last reply
        0
        • M Mundo Cani

          Hello, I'm new to the web development world and I'm hoping someone can point me in the right direction. I have an asp.net website (I'm using a starterkit from www.asp.net). I want to apply a different stylesheet if the client is a mobile device. I'm using a plugin that gives me the client device's display settings. If the display is below a certain resolution I want to use mobile.css. Otherwise, I want to use default.css. My understanding is that the style gets applied on the server when a request is made, and the resulting html is returned to the client. But I want the decission as to what style gets applied to be made by the client. How can I go about using javascript to change the stylesheet on the fly? Or, if I'm barking up the wrong tree, is there a way for me to program this functionality in the codebehind (I don't think there is, as the decission would have to be made on the client...)? Thanks for your help! (I'm a total noob in this area!)

          Ian

          J Offline
          J Offline
          Johnny
          wrote on last edited by
          #4

          You can use the 'link[^]' tag to identify the CSS file, with the media attribute specifying what device the file should be used for.

          M 1 Reply Last reply
          0
          • J Johnny

            You can use the 'link[^]' tag to identify the CSS file, with the media attribute specifying what device the file should be used for.

            M Offline
            M Offline
            Mundo Cani
            wrote on last edited by
            #5

            Thanks! I'll give this a try.

            Ian

            1 Reply Last reply
            0
            • M Mundo Cani

              Hello, I'm new to the web development world and I'm hoping someone can point me in the right direction. I have an asp.net website (I'm using a starterkit from www.asp.net). I want to apply a different stylesheet if the client is a mobile device. I'm using a plugin that gives me the client device's display settings. If the display is below a certain resolution I want to use mobile.css. Otherwise, I want to use default.css. My understanding is that the style gets applied on the server when a request is made, and the resulting html is returned to the client. But I want the decission as to what style gets applied to be made by the client. How can I go about using javascript to change the stylesheet on the fly? Or, if I'm barking up the wrong tree, is there a way for me to program this functionality in the codebehind (I don't think there is, as the decission would have to be made on the client...)? Thanks for your help! (I'm a total noob in this area!)

              Ian

              J Offline
              J Offline
              JimmyRopes
              wrote on last edited by
              #6

              ibowler wrote:

              I want to apply a different stylesheet if the client is a mobile device.

              Put something like this in the <head> section of the page. <style type="text/css" media="all"> @import "./styles/layout.css"; @import "./styles/presentation.css"; </style> <style type="text/css" media="screen"> @import "./styles/screen.css"; </style> <style type="text/css" media="print"> @import "./styles/print.css"; </style> <style type="text/css" media="handheld"> @import "./styles/handheld.css"; </style> CSS 2 Media Types[^] The media=all would be a general layout (header, body, footer, navigation, etc.) and presentation (color, background, etc.) for any media and the specialized by device style sheets override the things specific to the particular device.

              Simply Elegant Designs JimmyRopes Designs
              Think inside the box! ProActive Secure Systems
              I'm on-line therefore I am. JimmyRopes

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups