开发者

CSS, jQuery and IE. [closed]

开发者 https://www.devze.com 2023-03-23 19:44 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing th
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 9 years ago.

Improve this question 开发者_运维知识库

jQuery is a good choice to write the CSS code for IE-browsers or not? Many times I am facing with this problem. Sometimes it is so difficult to understand how to rewrite the code for all browsers including IE, sometimes I use jQuery to change the small pieces of code, but there is a problem, if user's internet bandwidth is weak, jQuery loads the CSS after the page is fully loaded, it is always like this, and the new users can do their bad impression about the site, and so on. Well, any advices to improve this?


jQuery loads the CSS after the page is fully loaded

jQuery should not be responsible for loading all your CSS. Hopefully this is not what you meant.

However, if you are talking about the flash of ugliness that can appear before all the javascript is done executing, one technique is to write specific CSS for you users without javascript. The idea is basically this:

<html class="no-js">

Then when jQuery loads, immediately call something like this:

$('html').removeClass('no-js').addClass('js');

Then you can use this selector in CSS to target elements when jQuery is or is not loaded or enabled.

.my-widget {
    /* default style */
}
.js .my-widget {
    /* style with javascript */
}
.no-js .my-widget {
    /* style without javascript */
}

Taken from the HTML5Boilerplate docs (one place this technique is used):

I prefer writing explicit styles for the user without JavaScript. Most of my sites expect JavaScript so that would mean prefixing a good 60% of my CSS selectors with .js. Alternatively I can have a few targeted .no-js overrides and tackle that case. More here: http://paulirish.com/2009/avoiding-the-fouc-v3/ and http://paulirish.com/2009/avoiding-the-fouc-v3/#comment-34951

In general though, try to make sure everything looks good without javascript, and use js for enhancements.

0

精彩评论

暂无评论...
验证码 换一张
取 消