【问题标题】:Why is my HTML link to external css not working?为什么我的指向外部 CSS 的 HTML 链接不起作用?
【发布时间】:2021-01-11 04:42:28
【问题描述】:

我创建了一个名为 css 的单独文件夹,并在其中创建了一个 styles.css 页面。请告诉我为什么我的预览页面现在没有显示我的 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>

【问题讨论】:

  • styles.css 是否与您的 HTML 文件位于同一文件夹中。
  • 控制台中是否显示任何错误?您是否在开发工具的“网络”窗格中看到对 styles.css 的请求?如果是这样,它是否成功完成?状态是什么,响应(如果有)是什么样的?路径是否符合您的预期?这些将是调试此问题的主要方法。

标签: html css


【解决方案1】:

包含路径有两个选项:

  1. 亲戚
  2. 修复

相对#Sample 1

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

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

相对#Sample 2

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

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

固定#Sample

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

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

【讨论】:

    【解决方案2】:

    我需要将完整路径放在链接 href 而不是“styles.css”

    轻松解决

    【讨论】:

      【解决方案3】:

      请在您的项目中遵循以下步骤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" />

      【讨论】:

        【解决方案4】:

        尝试先删除类型,然后将 href 值替换为 /css/style.css

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-08-24
          • 1970-01-01
          • 2023-04-08
          • 1970-01-01
          • 2011-02-19
          • 1970-01-01
          相关资源
          最近更新 更多