


Learn the basic framework construction principles and implementation methods of CSS
With the rapid development of the Internet, the design of web pages has received more and more attention. As one of the important parts of web design, CSS has attracted much attention for its principles and implementation methods of making the basic framework of web pages. This article will explain the principles and implementation methods of using CSS to create the basic framework of web pages through specific code examples.
1. Basic syntax of HTML and CSS
Before understanding the basic framework of CSS for making web pages, we need to first understand the basic syntax of HTML and CSS, which will help to better understand the use of CSS. .
- HTML basic syntax
HTML is the basic language of web pages, which is used to define the content and structure of web pages. A basic HTML structure is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>网页标题</title> </head> <body> 网页内容 </body> </html>
Among them, <!DOCTYPE html>
is used to define the document type, and the <html>
tag is used to define The root element of the document, the <head>
tag is used to define the header information of the web page, the <meta>
tag is used to set the metadata of the web page, <title> The ;
tag is used to define the title of the web page, and the <body>
tag is used to define the main content of the web page.
- Basic Syntax of CSS
CSS is the language of web page layout and style. It is used to control the display effect of various HTML elements in web pages. A basic CSS structure is as follows:
选择器 { 属性1: 值1; 属性2: 值2; 属性3: 值3; }
Among them, the selector is used to select the HTML element that needs to be styled, and the curly brackets are the specific style settings, including attributes and values.
2. The principle of making basic framework of web pages with CSS
The principle of making basic framework of web pages with CSS is very simple. It is to set the position, size, background, border, spacing and other style attributes of HTML elements to achieve the purpose of layout. The following will introduce in detail the implementation method of CSS to create the basic framework of web pages.
- Set the basic style of the web page
Before we start making the basic framework of the web page, we need to set the basic style of the web page, such as setting the background color, font, and font size of the web page wait.
body { background-color: #f5f5f5; /* 设置网页的背景颜色 */ font-family: Arial, sans-serif; /* 设置字体 */ font-size: 16px; /* 设置字号 */ }
- Define the layout of a web page
The layout of a web page refers to the position and size of each HTML element in the web page. Before implementing the web page layout, we need to define the containing block and document flow of the web page.
- Inclusion block
The inclusion block refers to the area where the HTML element is located. Its size and position determine how the HTML element is positioned. You can define the size of the containing block by setting properties such as width
, height
, padding
, border
, margin
, etc. and location.
- Document flow
Document flow refers to the flow direction of HTML elements in a web page, which is divided into block-level elements and inline elements. Block-level elements occupy an exclusive line and occupy the entire width of their parent element; inline elements are arranged in the same line, and the width is determined by the content. You can control the layout of elements by setting the display
attribute.
/* 定义网页的包含块 */ .container { width: 960px; /* 宽度为960px */ margin: 0 auto; /* 居中 */ padding: 20px 0; /* 上下各留20像素的padding */ } /* 定义网页的布局方式 */ .header { display: block; /* 块级元素 */ height: 100px; /* 高度为100px */ background-color: #333333; /* 背景为黑色 */ color: #ffffff; /* 文字为白色 */ } .nav { display: block; /* 块级元素 */ height: 40px; /* 高度为40px */ background-color: #f5f5f5; /* 背景为灰色 */ } .content { display: block; /* 块级元素 */ margin: 20px 0; /* 上下各留20像素的margin */ } .footer { display: block; /* 块级元素 */ height: 80px; /* 高度为80px */ background-color: #333333; /* 背景为黑色 */ color: #ffffff; /* 文字为白色 */ }
- Defining the style of HTML elements
After defining the layout of the web page, we need to define the style of each HTML element.
- Set text style
You can set font-size
, color
, font-weight
, line-height
and other attributes to control the size, color, thickness, line height, etc. of the text.
h1 { font-size: 32px; /* 设置标题字号为32px */ color: #333333; /* 设置标题颜色为黑色 */ font-weight: bold; /* 设置标题字体为粗体 */ line-height: 1.5; /* 设置字行距为1.5倍 */ } p { font-size: 16px; /* 设置正文字号为16px */ color: #666666; /* 设置正文颜色为灰色 */ line-height: 1.5; /* 设置字行距为1.5倍 */ }
- Set border and background styles
You can set border
, background-color
, background- attributes such as image
to control the borders and background of HTML elements.
.nav li { display: inline-block; /* 行内块元素 */ border: none; /* 取消边框 */ padding: 0 15px; /* 左右各留15像素的padding */ line-height: 40px; /* 文字与底部对齐 */ background-color: #f5f5f5; /* 背景颜色为灰色 */ } .button { display: inline-block; /* 行内块元素 */ border: 1px solid #cccccc; /* 设置边框 */ padding: 5px 10px; /* 上下各留5像素,左右各留10像素的padding */ background-color: #ffffff; /* 背景颜色为白色 */ color: #333333; /* 文字颜色为黑色 */ }
3. Method of implementing the basic framework of making web pages with CSS
After understanding the principle of making the basic framework of web pages with CSS, we can deepen our understanding through specific code implementation.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>CSS制作网页基本框架</title> <style> body { background-color: #f5f5f5; font-family: Arial, sans-serif; font-size: 16px; } .container { width: 960px; margin: 0 auto; padding: 20px 0; } .header { display: block; height: 100px; background-color: #333333; color: #ffffff; } .nav { display: block; height: 40px; background-color: #f5f5f5; } .nav li { display: inline-block; border: none; padding: 0 15px; line-height: 40px; background-color: #f5f5f5; } .content { display: block; margin: 20px 0; } h1 { font-size: 32px; color: #333333; font-weight: bold; line-height: 1.5; } p { font-size: 16px; color: #666666; line-height: 1.5; } .button { display: inline-block; border: 1px solid #cccccc; padding: 5px 10px; background-color: #ffffff; color: #333333; } .footer { display: block; height: 80px; background-color: #333333; color: #ffffff; } </style> </head> <body> <div class="container"> <div class="header"> <h1 id="网页标题">网页标题</h1> </div> <div class="nav"> <ul> <li>导航1</li> <li>导航2</li> <li>导航3</li> <li>导航4</li> </ul> </div> <div class="content"> <h2 id="文章标题">文章标题</h2> <p>文章内容</p> <p>文章内容</p> <p><a href="#" class="button">按钮</a></p> </div> <div class="footer"> <p>版权信息</p> </div> </div> </body> </html>
The above code implements a basic web page layout, including the title, navigation, content and footer of the web page. By setting the corresponding CSS properties, the position, size, background, style and other effects of each part are achieved.
4. Summary
This article introduces the principles and implementation methods of CSS to create the basic framework of web pages. Through specific code examples, it explains how CSS styles HTML elements and implements web page layout. Understanding and mastering this knowledge can allow us to better express our creativity and achieve results in web design and development.
The above is the detailed content of Learn the basic framework construction principles and implementation methods of CSS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

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.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text
