Should I load responsive design via JS or CSS [closed]

心不动则不痛 提交于 2019-12-08 12:42:07

问题


I am looking to make a slightly responsive design. I was curious to know how people feel on loading a responsive design, should I load in a new css file and use JS to define the screen size. Or should I create media queries inside the current css file and just go from there. Looking for opinion on speed and what people feel is the more optimal approach.


回答1:


Putting everything regarding styles in the CSS files is the best practice.

  • HTML => Structure
  • CSS => Styles
  • JS => Logic

The more you separate concerns, the easier your code will be to mantain.




回答2:


As javascript might be disabled you should use CSS-only for the responsive purposes.

If you really can't do without javascript (for moving an element in the dom for example) make sure that you've got some fallback css for non-js-enabled users.




回答3:


In fact very very few users will disable javascript, unless they are in emergency(say, if they only have outdated mobile phone because their new ones have run out of batteries). If your site is not toward these situations, use javascript without concerning that users will disable.

Generally, putting media queries in one css file will be a good choice if the file size is reasonalbe, since one file makes fewer request than seperated files.

Javascript, on the other hand, is the very fallback because old IEs do not support media queries.

You can refer to some frameworks such as bootstrap. An implementation outdoes all answers.



来源:https://stackoverflow.com/questions/16216764/should-i-load-responsive-design-via-js-or-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!