Proficient in CSS DIV web page style and layout CSS_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:51:39
Original
1299 people have browsed it

CSS, the English name is Cascading Style Sheet, and the Chinese name is Cascading Style Sheet, is a markup language used to control page styles and allow the separation of style information from web content. DIV CSS is a WEB design standard. It is a The layout method of web pages. Different from the traditional way of positioning through table layout, it can realize the separation of web page content and presentation. When it comes to DIV CSS combination, we have to start with XHTML. XHTML is a new language optimized and improved on the basis of HTML (a subset of the Standard Universal Markup Language). It aims to adapt to more needs of future network applications based on XML applications and powerful data conversion capabilities. "DIV CSS" is actually a misnomer, and the standard name should be XHTML CSS. Because DIV and Table are both tags in XHTML or HTML language, and CSS is just a form of expression.

Next, the editor will start with the most basic CSS.DIV web page style and layout, slowly introduce it, go in depth bit by bit, and then analyze it slowly with examples, hoping it will be helpful to everyone. Usually when we learn CSS, we should try our best to refer to other websites when writing CSS. For example, Baidu, Google, etc., by learning the CSS code of other websites, you can quickly get a different feel for the page design, and it is easier to get started. We call this "standing on the shoulders of giants." Today I will briefly introduce the basic concepts of CSS and the basic syntax of CSS. First, let's look at a picture:

Next, the editor will follow the context of this picture and gradually increase the basic knowledge of CSS.

A first look at CSS

Concept: CSS (Cascading Style Sheet), translated into Chinese as Cascading Style Sheet, is used to control web page styles and allow A markup language that separates style information from web page content.

Use CSS to control the page: There are four ways to control the page with CSS: inline style, inline style, link style and imported style. For slightly larger web pages, we will use the link style because it separates HTML and CSS to facilitate later maintenance and is clear and clear.

Basic syntax

For CSS selectors, that is, which html objects we select for CSS style control, there are three types: tag selectors, category selectors and ID selector, next, the editor will introduce these three selectors in detail.

Tag selector:

Let’s look at an example code and its display:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>Untitled Document</title><style type="text/css">h1{color:#0000FF;font-size:40px;}</style></head><body><h1>CSS选择器</h1><h1>CSS选择器</h1></body></html>
Copy after login

The effect is as follows:

Category selector: Let’s continue talking about the category selector: which is what we often call .class.

Comparing the tag selector above, we can easily see that only h1 has become .class; no other changes can be seen, so let’s see how to apply it in the code. Let’s take a look at an example code and its display effect:

<html><head><title>class选择器</title><style type="text/css"><!--.one{	color:red;			/* 红色 */	font-size:18px;		/* 文字大小 */}.two{	color:green;		/* 绿色 */	font-size:20px;		/* 文字大小 */}.three{	color:cyan;			/* 青色 */	font-size:22px;		/* 文字大小 */}--></style>   </head><body>	<p class="one">class选择器1</p>	<p class="two">class选择器2</p>	<p class="three">class选择器3</p>	<h3 class="two">h3同样适用</h3></body></html>
Copy after login
Analyze the above code. Each of our P tags is controlled by a class, and one class="one" corresponds to one .one{}, and then add attributes to .one. The effect is as follows:

We can see that this h3 and .two have the same effect, but The fonts are different, that is the difference between h3's default font and class. The advantage of using class is that it allows users to fully customize and this class can be used repeatedly. This is what our p mark and h3 mark show.

ID Selector

Let’s take a look at an example code and its display:

<html><head><title>ID选择器</title><style type="text/css"><!--#one{	font-weight:bold;		/* 粗体 */}#two{	font-size:30px;			/* 字体大小 */	color:#009900;			/* 颜色 */}--></style>   </head><body>	<p id="one">ID选择器1</p>	<p id="two">ID选择器2</p>	<p id="two">ID选择器3</p>	<p id="one two">ID选择器3</p></body></html>
Copy after login
Compared with the category selector, there is an extra "#". The difference between ID and class is: ID does not allow two identical IDs. The display effect is as follows:

CSS declarations

There are three types of CSS declarations, collective declarations, global declarations and nested declarations. Take a look at the following two examples:

<html><head><title>集体声明</title><style type="text/css"><!--h1, h2, h3, h4, h5, p{			/* 集体声明 */	color:purple;				/* 文字颜色 */	font-size:15px;				/* 字体大小 */}h2.special, .special, #one{		/* 集体声明 */	text-decoration:underline;	/* 下划线 */}--></style>   </head><body>	<h1>集体声明h1</h1>	<h2 class="special">集体声明h2</h2>	<h3>集体声明h3</h3>	<h4>集体声明h4</h4>	<h5>集体声明h5</h5>	<p>集体声明p1</p>	<p class="special">集体声明p2</p>	<p id="one">集体声明p3</p></body></html>
Copy after login
Effect As follows:

The following example is a nested statement, which can help us find the area we want to control very accurately:

<html><head><title>CSS选择器的嵌套声明</title><style type="text/css"><!--p b{							/* 嵌套声明 */	color:maroon;				/* 颜色 */	text-decoration:underline;	/* 下划线 */}--></style>   </head><body>	<p>嵌套使<b>用CSS</b>标记的方法</p>	嵌套之外的<b>标记</b>不生效</body></html>
Copy after login
The effect is as follows:

CSS inheritance, please click for details. Let’s take a look at the code and running effect of an example:

                                                                                                                                                 

Message from the editor: In this blog post, the editor mainly introduces some basic knowledge of CSS. Generally speaking, the introduction is divided into two parts, one is a preliminary exploration of CSS, and the other is the basic syntax of CSS. , a preliminary exploration of CSS including concepts and using CSS to control pages. The basic syntax of CSS includes three aspects, namely CSS selectors, CSS declarations, and CSS inheritance. With CSS, our interface instantly comes alive and moves, making our Internet world more colorful and infinitely beautiful. BS learning, unfinished, to be continued...

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