Home Web Front-end HTML Tutorial Proficient in CSS DIV web page style and layout CSS_html/css_WEB-ITnose

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

Jun 24, 2016 am 11:51 AM

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...

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

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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

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 &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

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 &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

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 &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

See all articles