Background from CSS not working in Base.html

喜你入骨 提交于 2021-01-28 12:02:08

问题


The following base.html code is not implementing the gradient background from the css file that is in the same folder.

base.html:

<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" text="text/css" href="templates/css/style.css">
  </head>

<body>
<h1>hi</h1>
</body>
</html>

style.css:

body {
background: linear-gradient(to bottom, #faaca8, #ddd6f3);
background-repeat: no-repeat;
background-size: cover;
width: 100%;
height: 100%;

}


回答1:


If this is not working, the problem is going to be the fact that you are referring to a different directory than you are wanting for the style.css folder. If it's in the same folder, please change the href in the link to href="style.css".

This is assuming you have one folder with the base.html and in the SAME folder, there is also the style.css stylesheet .

If it's based on the root directory, you would use /style.css , or on the folder before, ../foldername/style.css. For more, read here.




回答2:


text="text/css" should read type="text/css"




回答3:


Put the css codes inside the body tag or you can do it like this

   body {
    background: linear-gradient(to bottom, #faaca8, #ddd6f3);
    background-repeat: no-repeat;
    background-size: cover;
    width: 100%;
    height: 100%;
    <!doctype html>
    <html lang="en">
      <head>
    <link rel="stylesheet" type="text/css" href="style.css">  </head>
    
    <body>
    <h1>hi</h1>
    
    
   
    </body>
    </html>


来源:https://stackoverflow.com/questions/59187032/background-from-css-not-working-in-base-html

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