简体   繁体   English

Visual Studio 2010不链接CSS文件

[英]Visual Studio 2010 Not Linking CSS File

I currently have a css file that I want to link in visual studio. 我目前有一个要在Visual Studio中链接的CSS文件。 I have included the file in my project yet it is still not working. 我已将该文件包含在我的项目中,但仍无法正常工作。

I am simply using css to change the body background. 我只是使用CSS更改主体背景。 Here is my code: 这是我的代码:

Css - folder: /css/Style.css: CSS -文件夹:/css/Style.css:

body 
{
   background-image:  url('Images/body-background.jpg');
   background-repeat: repeat-x;
}

Html HTML

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>My Website</title>

        <link rel="stylesheet" type="text/css" href="css/Style.css" />
    </head>

    <body>
        <div id="header">
        </div>

        <div id="page-wrap">
            <ul id="nav">
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
            </ul>

            <p>Main Content</p>
        </div>

        <div id="footer">
        </div>
    </body>
</html>

It all works perfectly when I put the style internally in the head it works perfectly. 当我将样式放在内部时,一切都完美地工作了。 What's going on? 这是怎么回事?

The link in the css file to your image is relative to the css file. css文件中指向图像的链接是相对于css文件的。

try 尝试

background-image:  url('/Images/body-background.jpg');

to get it from root, or 从根获得它,或者

background-image:  url('../Images/body-background.jpg');

to get it relative to the css file. 使其相对于css文件。

This will work in css file. 这将在css文件中工作。

body 
{
   background-image:  url('/Images/body-background.jpg');
   background-repeat: repeat-x;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM