简体   繁体   English

为什么我的 HTML 链接到外部 css 不起作用?

[英]Why is my HTML link to external css not working?

Ive created a separate folder called css and created a styles.css page within it.我创建了一个名为 css 的单独文件夹,并在其中创建了一个 styles.css 页面。 Please let me know why my preview page is not showing my css now.请告诉我为什么我的预览页面现在没有显示我的 css。

<!DOCTYPE html>
<html>

    <head>
    
      <meta charset="utf-8">
      <meta name="description"Yasin Zahir>
      <title>Yaso's Personal Site</title>
      <link rel = "stylesheet"
      type = "text/css"
      href = "styles.css" />
    </head>

You have tow options for inclusion path:您有两个包含路径的选项:

  1. Relative相对的
  2. Fix使固定

Relative#Sample 1相对#样本 1

 -root directory
 -css
  stylesheet.css
 -index.html

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

Relative#Sample 2相对#示例 2

-root directory
 -css
   stylesheet.css
 -html
   index.html

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

Fixed#Sample固定#Sample

-root directory
 -css
   stylesheet.css
 -html
   index.html

    <link rel='stylesheet' type='text/css' href='[root directory]/css/stylesheet.css'>

I needed to put the full path on the link href instead of just "styles.css"我需要将完整路径放在链接href上,而不仅仅是“styles.css”

easy fix容易修复

Please follow following step in your project directory请在您的项目directory中执行以下步骤

 <.DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="description"Yasin Zahir> <title>Yaso's Personal Site</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> </head> </html> Follow this directory - root directory - css directory style.css - index.html or - root directory style.css index.html <link rel="stylesheet" type="text/css" href="style.css" />

try removing the type first, then replace the href value with /css/style.css尝试先删除类型,然后将 href 值替换为 /css/style.css

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

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