How to reference CSS into HTML
There are four ways to reference css style sheets. Use css styles directly in divs to create div+css web pages, use the style built-in style in html, use @import to reference external CSS files, and use link to reference external CSS files. Each has advantages and disadvantages, so today we will explain in detail the differences between these four methods.
Using different methods to reference css style sheets will ultimately achieve the same effect, but using css files applied in different methods will affect SEO and web page opening speed and efficiency. Next, we will explain the examples of how to reference CSS in HTML one by one
1. Embed CSS styles directly in HTML tag elements, such as
2. Insert the style statement code in the head part of the html header as follows:
<style type="text/css"> <!-- .ceshi {font-size:14px; color:#FF0000;}/*这里是设置CSS的样式内容*/ --> </style>
3. Use @import to reference external CSS files
<!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>css引用方法实例</title> <style type="text/css"> <!-- @import url(wcss.css);/*这里是通过@import引用CSS的样式内容*/ --> </style> </head> <body> <div class="ceshi">我是测试内容</div> </body> </html>
Code in Wcss.css file.ceshi {font-size:14px; color:#FF0000;}
It can be seen that there are similarities between using this method and using the built-in reference css style sheet method. Both need to use the style tag in the head of html to reference external css.
4. Use link to call external css files
Place To call the external wcss.css file to implement html reference css file
This method does not require the style tag, but directly refers to the external style by linking a style
It is generally recommended to use link to reference external css style methods.
Advantages of using link to reference external css
1. It is beneficial to SEO. Using this method to reference external css files will make the source code of the html page much smaller than directly adding css styles. , because search engine spiders do not crawl css files when crawling web pages, which results in very few html source codes, making spiders crawl faster and process less, which increases the weight of this web page and is beneficial to rankings.
2. Saving HTML allows the browser to separate threads when downloading web pages, just like loading a page and having two lines opening a page at the same time, making the web page open extra fast. (When the user browses this webpage, the html source code and css file are downloaded at the same time, making it faster)
3. It is convenient to modify the style of the webpage. You only need to modify the css style to modify the art style of the webpage. If on the website In this method of the project, since the entire site uses a common CSS style, it is quick and convenient to modify the style of the entire site.
These are the four ways to reference css style sheets. Friends who need them can save them. Please also continue to pay attention to other updates on this site.
Related recommendations:
The above is the detailed content of How to reference CSS into HTML. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
