Suppose I rolled up the main page of an online store, and gave it a background through the style.css file:

body { background: #000000 url('../img/background_1.jpg') no-repeat 3px 50%; } 

Now I need to make up the page "price list" of the same store, but there I already want the background background file to be "background_2.jpg". But if I use for the price list a link to the same style.css file, then there is already a rule for the body tag. How do they usually act in such situations?

  • one
    Usually they divide styles into several files according to logic. General - connects everywhere, private - on a specific page. - Duck Learns to Take Cover
  • one
    Write it in different css files or enclose the page background in the head in <style>...</style> - Yuri

1 answer 1

Yes, you can, CSS and invented in order to bring the site to a single style. So this is the norm. And in your case with the situation with the BODY tag and its personalization (you can apply to the rest as well) you can apply classes, for example with the DIV tag:

 div { width: 100px; height: 100px; } .page1 { background-image: url('https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/WsxUquz/4k-animation-abstract-motion-background-shine-light-bokeh-particles-loop_41kyra_o__S0000.jpg'); } .page2 { background-image: url('http://i14.beon.ru/29/60/246029/80/12763180/26189495_glyamur_.jpeg'); } 
 <div class="page1">text</div> <div class="page2">text</div> 

  • So you propose to add some class to the body tag specifically for this purpose? - Nikita
  • @ Nikita, and it will be more correct than clever people advise there! It is not correct in each html to write styles in the head. There are usually written exceptional styles that can relate to the plugin, but not the background, even if it is the body. You can share your css files, but it is advisable to use a collector (for example, gulp) so that the output (in the release) already contains no more than 2 style files. - HamSter