How to import CSS styles into HTML external style sheets

How to import CSS styles into HTML external style sheets

The link-in style is to put all the styles in one or more external style sheet files. This file has the extension of css. Through the link tag, the external style sheet (external style file named css) is linked to the HTML document. In this way, the structure and style can be divided into two files, which makes it easier to edit the style or structure.

The basic syntax is:

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

Tips: The shortcut key is link+tab

Specific steps

① Create HTML and CSS files separately, with the file names ending with .html and .css respectively.

In HTML, only the structure and the content that needs to be changed in style are written;
Only styles are written in css files.

For example:

HTML file write:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
</head>
<body>
	<div class="demo">Learn external style sheets with Zhang Wangwang</div>
	<div>Learn external style sheets with Zhang Wangwang</div>
	<div>Learn external style sheets with Zhang Wangwang</div>
	<div>Learn external style sheets with Zhang Wangwang</div>
</body>
</html>

css file write:

.demo{
	color: blue; 
}

At this point, the browser displays:

insert image description here

As can be seen from the above code, we have set the color of the first line "Learn external style sheets with Zhang Wangwang" to blue, but because there is no connection between the .html and .css files, the first line of text in the browser does not display the edited color.

②Insert into the <head> of HTML

<link rel="stylesheet" href="css file path" />

After that, press Ctrl+S and refresh the browser to display the following:

You can see that the first line of text has turned blue~

Notice

When practicing, it is best to put the .css file and the .html file in the same directory folder, and remember to save it first by pressing Ctrl+S after writing the style or structure, so that the results can be displayed better and faster.
The function of the link tag is to introduce external CSS styles into the current HTML page, and it is a bridge between HTML and CSS files.

This is the end of this article about how to introduce CSS styles into HTML external style sheets. For more relevant content about introducing CSS styles into HTML, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  HTML table cross-row and cross-column operations (rowspan, colspan)

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

Recommend

Detailed steps to delete environment variables in Linux

How to delete environment variables in Linux? Use...

How to create a trigger in MySQL

This article example shares the specific code for...

Summary of naming conventions for HTML and CSS

CSS naming rules header: header Content: content/c...

React passes parameters in several ways

Table of contents Passing parameters between pare...

How to purchase and initially build a server

I haven't worked with servers for a while. No...

Programs to query port usage and clear port usage in Windows operating system

In Windows operating system, the program to query...

How to deploy tomcat in batches with ansible

1.1 Building the Directory Structure This operati...

How to click on the a tag to pop up the input file upload dialog box

html Copy code The code is as follows: <SPAN cl...

Learn about TypeScript data types in one article

Table of contents Basic Types any type Arrays Tup...

js to realize web music player

This article shares simple HTML and music player ...

Automatic line breaks in html pre tags

At this time, you can use overflow:auto; (when the...

React implements double slider cross sliding

This article shares the specific code for React t...

Summary of several submission methods of HTML forms

The most common, most commonly used and most gener...