


In the development process of front-end websites, we all need to use CSS styles. CSS styles can effectively achieve more precise control over the layout, fonts, colors, backgrounds and other effects of the page. So how are these css style files or codes imported into html? This chapter will show you how to introduce CSS style files into HTML? As well as the difference between link and @import (code example) , let everyone understand how css styles are imported, focusing on the import of css style files. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. How to import CSS styles into HTML
HTML is mainly responsible for the content display of the web page, while the CSS file is responsible for the style of the web page content. The methods of using CSS styles in HTML include: inline, embedded, and external,
. The external style is divided into: link (link) and import (@import). ). [Recommended learning: css video tutorial]
Then let me introduce it to you:
1. Inline style --- -Code example using CSS
in HTML tags:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>行内式</title> </head> <body> <p style="color: red;font-size: 20px;">行内式行内式行内式行内式行内式行内式行内式行内式行内式<p> </body> </html>
Rendering:
within the line quoted by css The style can also be called inline style or line-level style. It is introduced directly inside the tag. The obvious advantage is that it is very convenient and efficient; but it also has the disadvantage of not being able to reuse the style. If the number of lines of code reaches a certain length, it will not be possible. Recommended. Inline CSS is often used as a test to find bugs in the code.
Advantages:
Without the style sheet file, efficiency can be improved at some point;
Use The style attribute has the strongest style effect and will override the same style effect of other introduction methods.
Disadvantages:
It is difficult to share styles with multiple elements, which is not conducive to code reuse;
HTML and CSS code are mixed, making it difficult for programmers and search engines to read.
2. Embedded --- write the CSS content in the head tag through the style tag
Code example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>内嵌式</title> <style> p{ background-color: #21B4BB; color: #fff; font-size: 20px; } </style> </head> <body> <p>内嵌式内嵌式内嵌式内嵌式内嵌式内嵌式内嵌式<p> </body> </html>
Rendering:
The embedded style referenced by css can also be called internal style or page-level style, and the whole thing is placed in the head tag Inside, define the style in the style tag, and the scope is limited to the elements of this page; if the code you write exceeds a few hundred lines, think about how annoying it is to pull the code page to the top every time, so it is maintainable. Sexually inferior.
Advantages: Like interline style sheets, no additional requests are generated, and it initially realizes the separation of structure and style, making it more suitable for single-page website applications.
Disadvantages: Since the internal style sheet is written in the HTML file, the page is impure, the file size is large, it is not conducive to web crawlers to obtain information, it is not conducive to maintenance, and styles cannot be shared between pages
3. External link---introducing external style sheets (css style files) through the link tag
##1) Link type (link)
Grammar:<link rel="stylesheet" type="text/css" href="css的路径" >Code example: HTML code:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>链接式</title> <link rel="stylesheet" type="text/css" href="style.css" > </head> <body> <p>链接式链接式链接式链接式链接式链接式链接式链接式链接式链接式链接式链接式<p> </body> </html>css style file --style.css code:
p{ font-size: 20px; color: #fff; background-color: #70DBDB; }Rendering:
2) Import (@import)
Syntax:<style type="text/css" media="screen"> @import url("CSS文件"); </style>Code example:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>导入式</title> <style type="text/css" media="screen"> @import url("style.css"); </style> </head> <body> <p>导入式导入式导入式导入式导入式导入式导入式导入式导入式<p> </body> </html>Rendering:
The import will load the CSS file after the entire web page is loaded, so this results in One problem is that if the web page is relatively large, the unstyled page will appear for a while, and then after a flash, the style of the web page will appear. This is an inherent flaw of imports.
3) Advantages and disadvantages of external connection
Advantages:- Code that implements structure and performance Complete separation
- Facilitates reuse and maintenance
- Because it is separated into separate files, the size of the HTML file is greatly reduced, thus allowing The page structure is easier to read by programmers and web crawlers
- It is friendly to search engines, allowing search engines to rate the page higher, which is beneficial to the page’s search engine ranking
- The external style sheet is cached on the user's computer after the user's first visit, and does not need to be loaded on the next visit
If there are many styles, the CSS file will become very large and difficult to find. In addition, one more CSS file means one more HTTP request, which will increase server pressure on a website with a large number of visits.
2. Link and import The difference between the formula (@import)
link is an XHTML tag. In addition to loading CSS, it can also define other transactions such as RSS; while @import belongs to the CSS category. Only CSS can be loaded; when
#link references CSS, it is loaded at the same time when the page is loaded; while @import requires the page to be loaded completely.
link is an XHTML tag and has no compatibility issues; while @import was proposed in CSS2.1 and is not supported by lower version browsers.
ink supports using Javascript to control the DOM to change the style; @import does not support it.
@import can introduce other style sheets into the CSS file; link does not support it.
(Learning video sharing: Getting started with web front-end)
The above is the detailed content of How to introduce css style into html? And the difference between link and @import (code example). For more information, please follow other related articles on the PHP Chinese website!

区别是:css是层叠样式表单,是将样式信息与网页内容分离的一种标记语言,主要用来设计网页的样式,还可以对网页各元素进行格式化;xml是可扩展标记语言,是一种数据存储语言,用于使用简单的标记描述数据,将文档分成许多部件并对这些部件加以标识。

在css中,rtl是“right-to-left”的缩写,是从右往左的意思,指的是内联内容从右往左依次排布,是direction属性的一个属性值;该属性规定了文本的方向和书写方向,语法为“元素{direction:rtl}”。

在css中,可以利用“font-style”属性设置i元素不是斜体样式,该属性用于指定文本的字体样式,当属性值设置为“normal”时,会显示元素的标准字体样式,语法为“i元素{font-style:normal}”。

在css3中,可以用“transform-origin”属性设置rotate的旋转中心点,该属性可更改转换元素的位置,第一个参数设置x轴的旋转位置,第二个参数设置y轴旋转位置,语法为“transform-origin:x轴位置 y轴位置”。

一、@Import引入普通类@Import引入普通的类可以帮助我们把普通的类定义为Bean。@Import可以添加在@SpringBootApplication(启动类)、@Configuration(配置类)、@Component(组件类)对应的类上。注意:@RestController、@Service、@Repository都属于@Component@SpringBootApplication@Import(ImportBean.class)//通过@Import注解把ImportBean

在css中,可用cursor属性去除a标签的鼠标样式,该属性用于定义鼠标指针在一个元素边界范围内所用的鼠标样式,属性值设置为none时,会去除元素的鼠标样式,设置为default时,显示默认箭头样式,语法为“a{cursor:none}”。

利用CSS也能创建像素创意动画!下面本篇文章给大家介绍一下用CSS box-shadow创建像素创意动画的方法,有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

深入解析:link与import的区别是什么?在开发网页或应用程序时,我们经常需要引入外部的CSS文件或JavaScript库来增强或定制我们的代码。在这个过程中,link和import是两种常用的方法。虽然它们的目的都是引入外部资源,但在具体的使用上存在一些区别。语法和位置:link:使用link标签将外部资源链接到HTML文件中,通常位于HTML文档的头


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
