Constantly wondering. CSS or JavaScript ?? If there is an opportunity to make some element on pure css and not to use js, then use this opportunity?
Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants sercxjo , aleksandr barakin , Streletz , Ivan Pshenitsyn , user194374 August 20 '16 at 12:30 .
The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .
- oneIf there is a pump, why bother with a mouth? - Jean-Claude
3 answers
Look at support for CSS capabilities in browsers. This is a key point. The Internet is full of solutions like "Slider on pure CSS!", But if it is built on CSS capabilities that are not always supported, it makes no sense to use such a solution in production.
Learn CSS code solutions and test CSS support on caniuse.com . If support suits you, use CSS solutions. Otherwise - JS.
- Good. And if I have a drop-down menu (built on js), and js is disabled in the browser, how will it work adequately? Use modernizr and think over two solutions? - Ilya Osmanov
- Stick to the progressive enhancement approach. Replace the drop-down menu with a series of links. Or place the links on a separate page, and enter the page with a normal link. And when loading unobtrusive js change the transition to a separate page on the Ajax request and display links in the drop-down menu. - Vitaly Emelyantsev
Of course! CSS is for layout and design, JS is for interactivity. There are of course exceptions when it is JS that is needed - but they are rare, and are usually associated with ultra-specific design features.
- Suppose the creation of a slider (just scrolling pictures, no buttons). Is it really so necessary to JS if it can be done on css? Or Tab creation - Ilya Osmanov
- @ Ilya Osmanov tabs - you need JS to catch a click, in a slider - to catch clicks of buttons. Where there is a slider without buttons - there the customer will want a slider with buttons. Well, in general - we need reactions to user actions: certainly JS - which manipulates css-classes of objects. If you just need beautiful, without the reaction of the user - of course just enough css. Use input: checkbox - to interact with css - this is a crutch. - Goncharov Alexander
- oneWhy crutch? I was just at the checkbox and thought - Ilya Osmanov
- @ Ilya Osmanov will want to do something more complicated, more interactive: css will not be able to do it anymore, you will have to rewrite it once. On JS, all this is done easier and the main thing is more obvious - to make a postulate that the code should be read: two. I do not recommend to drive nails shorter into the wall with a screwdriver) - Goncharov Alexander
Well, look:
CSS
-> Style
JavaScript
-> Logic
Talk about "
CSS
orJavaScript
?" In my opinion a bit not appropriate, because they can not replace each other, and the turnover is complementary.
The only place where they can be compared is the animation, in which JavaScript
will win due to the consumption of smaller resources in 10-fold size:
Shl. If you can solve the problem quickly on CSS
use it, if not, then definitely go to JS
, without wasting your time.