A brief summary of how to write paths when HTML files introduce external CSS files

A brief summary of how to write paths when HTML files introduce external CSS files

1. Import the basic style of external CSS files

Use the <link> tag to introduce an external style sheet, which usually has two attributes:

  • The href attribute indicates the path of the CSS file
  • rel="stylesheet" describes the relationship between the current page and the document specified by href. That is, the document connected by href is a new style sheet.
<link href="style.css" rel="stylesheet" />

2. Basic rules of the path

/ represents the root directory, use with caution
…/ represents the previous directory
…/…/ represents the two levels above the directory
/… represents the lower level directory
/…/… represents the next two levels of directories

3. Examples of common path writing

1. index.html and style.css files are in the same folder

Same folder situation

<link href="style.css" rel="stylesheet" />

2. The css file is in the same folder as the html file

insert image description here

<link href="c/style.css" rel="stylesheet" />

3. The parent folder of html and the parent folder of css files are in the same folder

As shown in the figure: there are folders b and b2 under folder a, style.css is in folder c under folder b, and index.html is in folder b2.

  • The idea of ​​writing the path at this time is: find the common parent folder of the index.html file and the style.css file. From the figure, it is folder a.
  • First, starting from the index.html file, that is, in the b2 folder at this time, first find the a folder (the parent directory of the b2 folder), that is: .../
  • Then find the style.css file from folder a, that is: b/c/style.css
  • Combined together: href="…/b/c/style.css"

insert image description here

<link href="../b/c/style.css" rel="stylesheet" />

This concludes this article on how to write paths when HTML files import external CSS files. For more information about how to import external CSS paths from HTML, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. We hope that everyone will support 123WORDPRESS.COM in the future!

<<:  CSS3 achieves infinite scrolling/carousel effect of list

>>:  CSS pseudo-element::marker detailed explanation

Recommend

Build a Docker image using Dockerfile

Table of contents Build a Docker image using Dock...

Explanation of the usage scenarios of sql and various nosql databases

SQL is the main trunk. Why do I understand it thi...

Description of the default transaction isolation level of mysql and oracle

1. Transaction characteristics (ACID) (1) Atomici...

The impact of limit on query performance in MySQL

I. Introduction First, let me explain the version...

Record the whole process of MySQL master-slave configuration based on Linux

mysql master-slave configuration 1. Preparation H...

An article to help you understand Js inheritance and prototype chain

Table of contents Inheritance and prototype chain...

JS implements simple calendar effect

This article shares the specific code of JS to ac...

Summary of discussion on nginx cookie validity period

Every visit will generate Cookie in the browser, ...

SQL to implement time series dislocation restoration case

Table of contents 1. Requirements description 2. ...

What to do if you forget the initial password of MySQL on MAC

The solution to forgetting the initial password o...

VUE+Canvas realizes the whole process of a simple Gobang game

Preface In terms of layout, Gobang is much simple...

CSS sets the list style and creates the navigation menu implementation code

1. Set the list symbol list-style-type: attribute...