Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have 2 style sheets as :
JavaScript
<link rel='stylesheet' type='text/css' href='style1.css' />
and

JavaScript
<link rel='stylesheet' type='text/css' href='style.css' />
Now the on basis of screen.width i have to set the style sheets for the page e.g.
If screen.width is greater then 1280 then want to set first style sheet else second.how to do this on page load.

Please help.


thanks

mohd wasif
Posted
Updated 23-Oct-12 0:19am
v2
Comments
Sergey Alexandrovich Kryukov 23-Oct-12 13:17pm    
Bad idea. The decent approach is to design the application page style which is resolution-tolerant, without measuring of actual resolution. (You should say not "resolution", but dimensions in pixels. Resolution (which is, say, dots per inch) is irrelevant.)
--SA

You don't need javascript you can set a media query

 
Share this answer
 
I would not recommend to use two different style sheets for this. Now a days mobiles, tabs and laptops are having many types of screen sizes. If you decide to handle that many resolutions you have to write that many style sheets. It is inconvenient to handle and also increase your page requests.

That's why professionals recommend to write media queries inside single style sheet. Like this


@media only screen and (min-width : 320px) and (max-width : 480px) {
/* mobile Styles */
}


@media only screen and (min-width : 481px) and (max-width : 800px) {
/*Tab Styles */
}


@media only screen and (min-width : 801px) and (max-width : 1024px) {
/*Desktops Styles */
}

Check it out this link
http://waybloggy.blogspot.com/2014/09/components-required-for-responsive-web.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900