简体   繁体   中英

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. Please let me know why my preview page is not showing my css now.

<!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

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

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

Relative#Sample 2

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

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

Fixed#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"

easy fix

Please follow following step in your project 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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