JS calls different CSS files depending on the screen size

Source: Internet
Author: User

Reason: Screen size is not the same, the site seems to always feel strange, so, for different size of the screen, write a different CSS, finished, to solve the problem is: how to screen size to reference different CSS, the following is the solution.

Workaround: First, a generic CSS file is referenced first in the head tag, as follows:

<link href= "styles/style.css" id= "CSS" rel= "stylesheet" type= "Text/css"/> This time, you will find that this and the usual reference to the CSS file is slightly different, that is, Added an ID, which adds an ID to the CSS ID. Next, get another JS, the code is as follows:
1234567891011121314 $(function() {            //判断是否宽屏            varwinWide = window.screen.width;            alert(winWide);            varwideScreen = false;            if(winWide <= 1024) {//1024及以下分辨率                $("#css").attr("href""Styles/Style1.css");                alert(‘小屏‘);            else{                $("#css").attr("href""Styles/Style.css");                alert(‘大屏‘);                wideScreen = true//是宽屏            }})

Well, the code is so simple, you crossing, you look at it ... Category: Front-end reprint: http://www.cnblogs.com/xmiao/p/6144355.html

JS calls different CSS files depending on the screen size

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.