CSS in HTML and main.css

Any ideas why this CSS code is not working when I put it in the main.css file? I am trying to make a fullscreen background.

<html> <head> <link rel="stylesheet" type="text/css" href="CSS/main.css"> <style> .bg { background-image: url("nuotraukos/bg.png"); min-height:100%; min-width: 100%; background-attachment: fixed; background-position: center; background-repeat: no-repeat; background-size: cover; } </style> </head> <body> <div class="bg"></div> </body> </html> 
+5
source share
2 answers

Nothing like your <link> . Check if the file really exists, and if the html page is in the same directory as the CSS folder. Otherwise, the file path is incorrect.

If the image does not appear, it is possible because it does not match the same path as .css , so you should also change the link.

Suppose your image is a single folder up the css file. Then you should change the url:

 url("../nuotraukos/bg.png"); 

It is also not recommended to use a div to set the background, so instead of using a div to set the background, set the background to <body> and stretch it.

 body { background-image: url("http://images.alphacoders.com/538/53823.jpg"); background-size:cover; } 
 <head> </head> <body> </body> 
+3
source

Maybe this will help if you change the path when placing main.css in the CSS folder?

 background-image: url("../nuotraukos/bg.png"); 
+2
source

Source: https://habr.com/ru/post/1239309/


All Articles