CSS Journey--The First Stop Why Use CSS_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:45:00
Original
1048 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

最后值得一提的是,尽量避免使用“内联样式”的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>
Copy after login

 

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

 

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!