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
HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

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

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

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