Define css if javascript is not enabled

前端 未结 8 1651
无人共我
无人共我 2020-12-10 14:58

I want to define .exampleclass img {height:250px} if javascript is not enabled. Is their anyway to undo this in javascript / jquery?

8条回答
  •  佛祖请我去吃肉
    2020-12-10 15:06

    The most elegant way is to have in your CSS something like:

    .exampleclass img {height:250px}
    .js .exampleclass img {height:auto;}
    

    and in your JS:

    var dd = document.documentElement;
    dd.className += ((dd.className == "") ? "js" : " js");
    

    so that the second CSS rule will override the first one in case JS is enabled

提交回复
热议问题