search
HomeWeb Front-endHTML TutorialCSS Journey--The First Stop Why Use CSS_html/css_WEB-ITnose

I don’t know how many programmers are like me. CSS has always been a weakness, so soft that my whole body feels numb. . . Now that the weakness has come, we can only find a way to solve it, so I took a look at the CSS Definitive Guide. Everyone said

The CSS Definitive Guide is relatively outdated, but the content is still relatively substantial, and the content is It's basically like talking to you, very comfortable. Okay, let's start with the text.

1: Why should you learn CSS

When you know the history of CSS, it is quite interesting. A long time ago, there was no css on the web, only some html. tags, such as p, h1...h5... div span, ul, etc. These html tags

are all html tags with specific meanings. In the past, people were very practical and did not pay attention to typesetting. As long as As long as the content is useful, just like the layout of the current blog garden, which is simple and beautiful, we coders also don’t care about this

as long as the article is useful, but what? Web users are not programmers. They don’t care about practical things. They care about appearance, coolness, and personality. In this case, Html will not be able to hold it.

The W3C organization is to satisfy these people. Appetite provides some tags to decorate HTML tags, such as strong, font, b, u, etc. . . Just like this.

<body>    <font size="20" color="red"><b>你好</b></font></body>

Then, programmers had the following complaints. . .

First: I have to write countless tags just to decorate a text, damn it. . . What a hassle. . .

Second: Madan, now our page structure is becoming more and more complex. These fonts and b cannot be reused at all, they are completely ruined. . . . Tall and hairy. . .

Third: The country is so poor now and bandwidth is so expensive. The size of my html is really huge, and the content actually only accounts for less than 1/10 of the html. . . It sometimes takes a few minutes for my clients to open. . . If this continues,

I will be unemployed. .

As a result, W3C has incurred a lot of criticism from online programmers. The original idea was to modify the structural content of html through some style html tags, but the result is now a mess. Moreover, the page structure is

out of balance. . . Faced with three major problems, W3C began to launch CSS, a cascading style sheet for decorating Html. Completely solves the three major problems raised by programmers. . .

2: How to solve the three major problems

1. The problem of countless tags

CSS uses rules to decorate the structural elements of each html , the structure of the rules adopts the method of "tag content declaration", such as:

1     <style type="text/css">2         p {3             font-size: 20px;4             color: red;5             margin: auto 0;6             width: 50%;7         }8     </style>

I think there is nothing much to say about this definition. In this case, we put all the decorative tags in html Take it out and put it into a special css rule. Everyone has seen the benefits of this. The separation of "content" and "display"

This solves the first complaint of programmers. .

2. Reuse of decorative tags.

Indeed, the original HTML decoration tags cannot be reused, which will naturally lead to page expansion. CSS uses rule groups to solve this problem. Write the rules first, and then decide which tags you want to use. , just apply the css definition that has been set under

. In this case, the problem of reuse is solved.

3. Volume expansion problem

If the first and second problems are not solved, the third problem will naturally occur, and I think there are others A series of chain reactions, so what methods did CSS take to solve it? In order to highlight the ultimate goal of CSS, we must

strictly separate "content" and "display" and achieve "separation" , then the css must be separately encapsulated into a special css file. In this case, not only can the tags of a single html page be reused, but it can even be reused on multiple pages

and multiple sites. Then the next question comes, what are the ways to reference css files? ? ? Which ones are not worth advocating?

3: How to reference css files

1. Link reference

When you drag css into vs, the default is link mode , link is originally a tag of xhtml, so we can also use js to dynamically add and control it. I think everyone knows this. Another interesting thing is that

can be used as a "candidate style sheet" , you can dynamically select the style you want in the browser. For example, I defined two css files below to let the page display red and blue backgrounds respectively.

Then we can dynamically switch the css style I want in the browser, which is quite interesting, although this function is relatively rare, because the screenshot is not Great, you can use "View" => "Style" in the toolbar.

2.import reference

This tag can also be imported, like below.

 1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 4     <title></title> 5     <style type="text/css"> 6         @import url(blue.css) 7     </style> 8 </head> 9 <body>10     hello world;11 </body>12 </html>

最后值得一提的是,尽量避免使用“内联样式”的style,如果这样的话,跟使用font,strong这样的标记几乎没有什么区别,就比如下面这样,所以我们尽量避免。

 1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5     <title></title> 6 </head> 7 <body style="color: red; margin: 0 auto"> 8     hello world; 9 </body>10 </html>

 

好了,第一篇大概就这么说了,后续的我们再延伸,周末愉快。

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

How to efficiently add stroke effects to PNG images on web pages?How to efficiently add stroke effects to PNG images on web pages?Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

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.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools