Hi guys,
i want to ask, is it possible to load css using javascript ???
because i have 2 css files, 1 for the desktop and the other one for the mobile browser/touch device
The issue here is that there are two CSS files targeted specifically for different environments, desktop & mobile.
Media queries could reduce this to a single CSS file but if the separate files are required then there is no reason that the 'media query' couldn't be in the head of the page to load the css file appropriate to the screen/device width.
Something like:
<link href="css/orig/phone.css" rel="stylesheet" type="text/css" media="all and (min-width: 300px) and (max-width: 320px)">
@Eric, why did you say "I disagree using css is many ways better", can you explain it a little bit ?
i'm still new so there's many thing i must learn @Paulie_D thanks for the answer
Paulie no I'm saying I believe media all is default. So if you exclude media all it will still target all.
Kiddo. My link explains why it's good. But I guess it comes down to what your using it for. From the sounds of it I guess media queries would be better in your case. Usually you use javascript to feed css when you don't want the css applied when JS is off.
Hi guys,
i want to ask, is it possible to load css using javascript ???
because i have 2 css files, 1 for the desktop and the other one for the mobile browser/touch device
It is indeed possible.
But sometimes using JavaScript isn't the best idea. Have you thought about using media queries instead?
Seconded. Use media queries instead of JavaScript.
Here's an introduction to media queries that Chris wrote: http://css-tricks.com/css-media-queries/
@rosspenman and @HugoGiraudel, thanks a lot guys.
I disagree using css is many ways better. Here are 7 clean ways to do it. FYI the last one is the best http://www.visibilityinherit.com/code/add-css-with-javascript.php
The issue here is that there are two CSS files targeted specifically for different environments, desktop & mobile.
Media queries could reduce this to a single CSS file but if the separate files are required then there is no reason that the 'media query' couldn't be in the head of the page to load the css file appropriate to the screen/device width.
Something like:
@Paulie_D default is all correct?
so you could just say media="() and ()
media = all will media types of which there are many.
If you want to limit it to screen devices (say you don;t want it for printing purposes) then you could change it to media="screen".
@Eric, why did you say "I disagree using css is many ways better", can you explain it a little bit ?
i'm still new so there's many thing i must learn
@Paulie_D thanks for the answer
Paulie no I'm saying I believe media all is default. So if you exclude media all it will still target all.
Kiddo. My link explains why it's good. But I guess it comes down to what your using it for. From the sounds of it I guess media queries would be better in your case. Usually you use javascript to feed css when you don't want the css applied when JS is off.