Two calling methods: 1. Use the link tag to call, the syntax is ""; 2 , use the "@import" keyword to call, the syntax is "".
The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.
CSS External Style Sheet
If the CSS style is placed in a file outside the web document, it is called an external style sheet, a CSS A style sheet document represents an external style sheet.
In fact, the external style sheet is a text file with the extension .css. When you copy the CSS style code into a text file and save it as a .css file, it is an external style sheet.
Two methods of calling external style sheets in html pages
External style sheets must be imported into the web page document before they can be used by the browser Identify and parse. External style sheet files can be imported into HTML documents in two ways.
1. Use the tag to call (link style)
Use the tag to call the external style sheet file:
<link href="外部样式表文件路径" rel="stylesheet" type="text/css" />
Description of each attribute:
#href attribute sets the address of the external style sheet file, which can be a relative address or an absolute address.
The rel attribute defines the associated document, which here indicates that the associated document is a style sheet.
The type attribute defines the type of imported file. Like the style element, text/css indicates a CSS text file.
Generally when defining the tag, three basic attributes should be defined, among which href is a must-set attribute.
Linking external style sheet files to HTML documents through HTML's tag is the most commonly used method for websites on the Internet, and it is also the most practical method. This method completely separates HTML documents and CSS files, achieves a complete separation of the structure layer and the presentation layer, and enhances the scalability of the web page structure and the maintainability of CSS styles.
Example: Use link style to apply styles to HTML code, which is easy to write and change.
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <link href="lianjie.css" type="text/css" rel="stylesheet" /> <link href="lianjie-2.css" type="text/css" rel="stylesheet" /> </head> <body> <p>我是被 lianjie-2.css 文件控制的,楼下的你呢??</p> <h3 id="楼上的-span-lianjie-css-span-nbsp-文件给我穿的花衣服">楼上的,<span>lianjie.css</span> 文件给我穿的花衣服。</h3> </body> </html>
In the above example, two CSS files are linked through link, and both are valid. This is why the website maker puts the public part into one CSS file, and the current page style Write a new style file.
lianjie.css File code:
h3{ font-weight: normal; /*取消标题默认加粗效果*/ background-color: #66CC99; /* 设置背景色 */ height: 50px; /*设置标签的高度*/ line-height:50px; /* 设置标签的行高 */ } span{ color: #FFOOOO; /* 字体颜色 */ font-weight:bold; /* 字体加粗 */ }
lianjie-2.css File code:
p{ color: #FF3333; /*字体颜色设置*/ font-weight: bold; /* 字体加粗 */ border-bottom: 3px dashed #009933; /* 设置下边框线 */ line-height: 30px; /* 设置行高 */ }
Linked style completely separates CSS code and HTML code to achieve structure and style The separation allows the HTML code to specifically build the page structure, while the beautification work is completed by CSS.
Benefits of link-based import of CSS styles:
CSS files can be placed in different HTML files to make all pages of the website unified in style;
Furthermore, putting the CSS code into a CSS file facilitates management and reduces code and maintenance time;
When the CSS file is modified, all applications that apply this CSS file The HTML files will all be updated without having to retrieve all the pages from the server and then upload them after modifications.
2. Use the @import keyword to call (import)
The @import directive is part of the CSS language. Use this directive when using it. Added to a
To associate with an external CSS file, use url instead of href, and put the path in parentheses;
<style type="text/css"> @import url("外部样式表文件路径"); </style>
After the @import keyword, use the url() function to include the address of the specific external style sheet file.
Example: Import the style sheets lianjie.css and daoru.css and write the background color of the
tag. Note that the imported style sheet and tag styles cannot be reversed.<html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> @import url(lianjie.css); @import url(daoru.css); body { background-color: #e4e929; } </style> </head> <body> <div> <p>我是被 lianjie-2.css 文件控制的,楼下的你呢??</p> <h3 id="褛上的-span-lianjie-css-span-文件给我穿的花衣服">褛上的,<span>lianjie.css</span>文件给我穿的花衣服。</h3> </div> </body> </html>
In the above example, it must be @import url("lianjie-2.css"); p{text-indent: 3em;}
, not p{text-indent:3em;} @import url("lianjie-2.css");
, otherwise the import effect will be invalid. In the CSS file, @import also needs to be placed at the front and the CSS style is added at the end, otherwise it will be invalid.
lianjie.css file code, the same as the previous example, that is, link type.
daoru.css file code:
@import url("lianjie-2.css"); p { text-indent: 3em; }
The difference between the two methods (link and @import)
tag belongs to html tag , and @import is a method provided by css. The tag can not only introduce css, but also do other things, while @import can only introduce css;
The difference in loading order: when a page is browsed, the css introduced by link will be loaded synchronously, while the css referenced by @import will not be loaded until all other elements have been downloaded;
Compatible Differences in nature: @import was only proposed in CSS2.1, so it is only supported by IE5 and above, and is not supported by lower version browsers. The tag does not have this problem;
When controlled using javascript When the DOM changes the style, you can only use the tag, because @import is not controllable by the DOM.
(Learning video sharing: Getting started with web front-end)
The above is the detailed content of What is the method to call external styles in html page. For more information, please follow other related articles on the PHP Chinese website!

HTML and React can be seamlessly integrated through JSX to build an efficient user interface. 1) Embed HTML elements using JSX, 2) Optimize rendering performance using virtual DOM, 3) Manage and render HTML structures through componentization. This integration method is not only intuitive, but also improves application performance.

React efficiently renders data through state and props, and handles user events through the synthesis event system. 1) Use useState to manage state, such as the counter example. 2) Event processing is implemented by adding functions in JSX, such as button clicks. 3) The key attribute is required to render the list, such as the TodoList component. 4) For form processing, useState and e.preventDefault(), such as Form components.

React interacts with the server through HTTP requests to obtain, send, update and delete data. 1) User operation triggers events, 2) Initiate HTTP requests, 3) Process server responses, 4) Update component status and re-render.

React is a JavaScript library for building user interfaces that improves efficiency through component development and virtual DOM. 1. Components and JSX: Use JSX syntax to define components to enhance code intuitiveness and quality. 2. Virtual DOM and Rendering: Optimize rendering performance through virtual DOM and diff algorithms. 3. State management and Hooks: Hooks such as useState and useEffect simplify state management and side effects handling. 4. Example of usage: From basic forms to advanced global state management, use the ContextAPI. 5. Common errors and debugging: Avoid improper state management and component update problems, and use ReactDevTools to debug. 6. Performance optimization and optimality

Reactisafrontendlibrary,focusedonbuildinguserinterfaces.ItmanagesUIstateandupdatesefficientlyusingavirtualDOM,andinteractswithbackendservicesviaAPIsfordatahandling,butdoesnotprocessorstoredataitself.

React can be embedded in HTML to enhance or completely rewrite traditional HTML pages. 1) The basic steps to using React include adding a root div in HTML and rendering the React component via ReactDOM.render(). 2) More advanced applications include using useState to manage state and implement complex UI interactions such as counters and to-do lists. 3) Optimization and best practices include code segmentation, lazy loading and using React.memo and useMemo to improve performance. Through these methods, developers can leverage the power of React to build dynamic and responsive user interfaces.

React is a JavaScript library for building modern front-end applications. 1. It uses componentized and virtual DOM to optimize performance. 2. Components use JSX to define, state and attributes to manage data. 3. Hooks simplify life cycle management. 4. Use ContextAPI to manage global status. 5. Common errors require debugging status updates and life cycles. 6. Optimization techniques include Memoization, code splitting and virtual scrolling.

React's future will focus on the ultimate in component development, performance optimization and deep integration with other technology stacks. 1) React will further simplify the creation and management of components and promote the ultimate in component development. 2) Performance optimization will become the focus, especially in large applications. 3) React will be deeply integrated with technologies such as GraphQL and TypeScript to improve the development experience.


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

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.