简体   繁体   English

如何让我的 css 链接到我的 html fie?

[英]How do i get my css to link to my html fie?

I'm using sublime text to create a website and my CSS file wont link to my HTML.我正在使用崇高的文本创建一个网站,我的 CSS 文件不会链接到我的 HTML。 I've looked this up and everything seems to be coded correctly (also saved in the same folder).我已经查过了,一切似乎都正确编码(也保存在同一个文件夹中)。 So I'm unsure what I'm doing wrong?所以我不确定我做错了什么?

HTML: HTML:

<head>
    <title>shannonkelseyann</title>
    <link href="styles/main.css" rel="stylesheet" type="text/css" />
</head>

<body>
    <h1>My portfolio</h1>
    <ul>
        <li>Home</li>
        <li><a href="page2.html">page 2</a></li>
        <li><a href="page3.html">page 3</a></li>
    </ul>
    <h2>This is my homepage</h2>
    <p>And all of my homepage content</p>
</body>

CSS: CSS:

 body { font-family: arial; background: red; }

If the CSS file is saved in the same folder as the HTML, you just have to use the file's name directly without /styles :如果 CSS 文件与 HTML 保存在同一文件夹中,则只需直接使用文件名而不使用/styles

<head>
    <title>shannonkelseyann</title>
    <link href="main.css" rel="stylesheet" type="text/css" />
</head>

welcome to Stackoverflow.欢迎来到 Stackoverflow。

If your css file really is in the same folder as your html file as you say in your question then you need to edit your link to reflect that.如果您的 css 文件确实与您在问题中所说的 html 文件位于同一文件夹中,那么您需要编辑链接以反映这一点。 At the moment you have:目前你有:

<link href="styles/main.css" rel="stylesheet" type="text/css" />

You're telling the browser that the style sheet is inside a folder "styles".您是在告诉浏览器样式表在文件夹“styles”中。 If it really is in the same folder as your html then you'd use:如果它确实与您的 html 位于同一文件夹中,那么您将使用:

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

What the href should be will depend on the folder structure on your server of where the css is compared to the html and what URL you are accessing the html page from. What the href should be will depend on the folder structure on your server of where the css is compared to the html and what URL you are accessing the html page from.

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

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