Table of Contents
1. Float positioning
2. position positioning
a. position:static|no positioning
b. position:relative | Relative positioning
c. position:absolute|Absolute positioning
Home Web Front-end HTML Tutorial css div web design (2) layout and positioning_html/css_WEB-ITnose

css div web design (2) layout and positioning_html/css_WEB-ITnose

Jun 24, 2016 pm 12:00 PM
position layout Web page design

In web design, it is very critical to be able to control the position of each module on the page. Different from the traditional table positioning, the css div positioning method is more flexible. This blog will introduce it to you. Layout and positioning of css divs.


1. Box model


As can be seen from the picture, the scope of the box model includes margin, border, padding, and content.

One thing to point out is that the box model representation in IE is slightly different from that in Firefox:

The content part of the IE box model includes border and pading.

The content part of the box model in Firefox does not include border and padding.


2. Element positioning

1. Float positioning

float means floating and plays an important role in CSS layout. Here are some examples An example.

<span style="font-size:18px;"><html><head><title>float属性 clear</title><style type="text/css"><!--body{	margin:5px;	font-family:Arial;	font-size:13px;}.block1{	padding-left:10px;	margin-right:10px;	float:left;					/* 块1向左浮动 */}h3{	background-color:#a5d1ff;	/* 标题的背景色 */	border:1px dotted #222222;	/* 标题边框 */	 clear:left;					/*清除float对左侧的影响 */}--></style>   </head><body>	<div class="block1"><img src="building2.jpg" border="0"></div>		<div>对于一个网页设计者来说,HTML语言一定不会感到陌生,因为它是所有网页制作的基础。但是如果希望网页能够美观、大方,并且升级方便,维护轻松,那么仅仅HTML是不够的,CSS在这中间扮演着重要的角色。本章从CSS的基本概念出发,介绍CSS语言的特点,以及如何在网页中引入CSS,并对CSS进行初步的体验。</div>	<h3>CSS的概念</h3>	<div>CSS(Cascading Style Sheet),中文译为层叠样式表,是用于控制网页样式并允许将样式信息与网页内容分离的一种标记性语言。</div></body></html></span>
Copy after login

The result at this time is


If float:left is commented out, the result is as follows:


2. position positioning

a. position:static|no positioning

position:static is the default value for positioning of all elements, generally No need to indicate, unless there is other positioning that needs to be cancelled.

<span style="font-size:18px;">#div-1 { position:static;}</span>
Copy after login

b. position:relative | Relative positioning

When using position:relative, you need top , bottom, left, right four attributes to cooperate to determine the position of the element.
If you want the div-1 layer to move 20px down and 40px to the left:
<span style="font-size:18px;">#div-1 { position:relative; top:20px; left:40px;}</span>
Copy after login

c. position:absolute|Absolute positioning

Use absolute Layers in front or behind the positioned layer will think that this layer does not exist and will not affect them at all.



3. z-index positioning:

The z-index attribute is used to position the upper and lower positions when overlapping.

<span style="font-size:18px;"><html><head><title>z-index属性</title><style type="text/css"><!--body{	margin:10px;	font-family:Arial;	font-size:13px;}#block1{	background-color:#fff0ac;	border:1px dashed #000000;	padding:10px;	position:absolute;	left:20px;	top:30px;	z-index:1;					/* 高低值1 */}#block2{	background-color:#ffc24c;	border:1px dashed #000000;	padding:10px;	position:absolute;	left:40px;	top:50px;	z-index:0;					/* 高低值0 */}#block3{	background-color:#c7ff9d;	border:1px dashed #000000;	padding:10px;	position:absolute;	left:60px;	top:70px;	z-index:-1;					/* 高低值-1 */}--></style>   </head><body>	<div id="block1">AAAAAAAA</div>	<div id="block2">BBBBBBBB</div>	<div id="block3">CCCCCCCC</div></body></html></span>
Copy after login

The results are as follows:



The above is the css div Layout and positioning, in the next blog I will introduce to you the mixed use of css and javascript, css and jquery, and css and ajax.

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to send web pages to desktop as shortcut in Edge browser? How to send web pages to desktop as shortcut in Edge browser? Mar 14, 2024 pm 05:22 PM

How to send web pages to the desktop as a shortcut in Edge browser? Many of our users want to display frequently used web pages on the desktop as shortcuts for the convenience of directly opening access pages, but they don’t know how to do it. In response to this problem, the editor of this issue will share the solution with the majority of users. , let’s take a look at the content shared in today’s software tutorial. The shortcut method of sending web pages to the desktop in Edge browser: 1. Open the software and click the "..." button on the page. 2. Select "Install this site as an application" in "Application" from the drop-down menu option. 3. Finally, click it in the pop-up window

What should I do if the images on the webpage cannot be loaded? 6 solutions What should I do if the images on the webpage cannot be loaded? 6 solutions Mar 15, 2024 am 10:30 AM

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

Retro trend! HMD and Heineken jointly launch flip phone: transparent shell design Retro trend! HMD and Heineken jointly launch flip phone: transparent shell design Apr 17, 2024 pm 06:50 PM

According to news on April 17, HMD teamed up with the well-known beer brand Heineken and the creative company Bodega to launch a unique flip phone - The Boring Phone. This phone is not only full of innovation in design, but also returns to nature in terms of functionality, aiming to lead people back to real interpersonal interactions and enjoy the pure time of drinking with friends. Boring mobile phone adopts a unique transparent flip design, showing a simple yet elegant aesthetic. It is equipped with a 2.8-inch QVGA display inside and a 1.77-inch display outside, providing users with a basic visual interaction experience. In terms of photography, although it is only equipped with a 30-megapixel camera, it is enough to handle simple daily tasks.

ZTE 5G portable Wi-Fi U50S goes on sale for NT$899 at first launch: top speed 500Mbps ZTE 5G portable Wi-Fi U50S goes on sale for NT$899 at first launch: top speed 500Mbps Apr 26, 2024 pm 03:46 PM

According to news on April 26, ZTE’s 5G portable Wi-Fi U50S is now officially on sale, starting at 899 yuan. In terms of appearance design, ZTE U50S Portable Wi-Fi is simple and stylish, easy to hold and pack. Its size is 159/73/18mm and is easy to carry, allowing you to enjoy 5G high-speed network anytime and anywhere, achieving an unimpeded mobile office and entertainment experience. ZTE 5G portable Wi-Fi U50S supports the advanced Wi-Fi 6 protocol with a peak rate of up to 1800Mbps. It relies on the Snapdragon X55 high-performance 5G platform to provide users with an extremely fast network experience. Not only does it support the 5G dual-mode SA+NSA network environment and Sub-6GHz frequency band, the measured network speed can even reach an astonishing 500Mbps, which is easily satisfactory.

Teclast M50 Mini tablet is here: 8.7-inch IPS screen, 5000mAh battery Teclast M50 Mini tablet is here: 8.7-inch IPS screen, 5000mAh battery Apr 04, 2024 am 08:31 AM

According to news on April 3, Taipower’s upcoming M50 Mini tablet computer is a device with rich functions and powerful performance. This new 8-inch small tablet is equipped with an 8.7-inch IPS screen, providing users with an excellent visual experience. Its metal body design is not only beautiful but also enhances the durability of the device. In terms of performance, the M50Mini is equipped with the Unisoc T606 eight-core processor, which has two A75 cores and six A55 cores, ensuring a smooth and efficient running experience. At the same time, the tablet is also equipped with a 6GB+128GB storage solution and supports 8GB memory expansion, which meets users’ needs for storage and multi-tasking. In terms of battery life, M50Mini is equipped with a 5000mAh battery and supports Ty

Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Honor Magic V3 debuts AI defocus eye protection technology: effectively alleviates the development of myopia Jul 18, 2024 am 09:27 AM

According to news on July 12, the Honor Magic V3 series was officially released today, equipped with the new Honor Vision Soothing Oasis eye protection screen. While the screen itself has high specifications and high quality, it also pioneered the introduction of AI active eye protection technology. It is reported that the traditional way to alleviate myopia is "myopia glasses". The power of myopia glasses is evenly distributed to ensure that the central area of ​​​​sight is imaged on the retina, but the peripheral area is imaged behind the retina. The retina senses that the image is behind, promoting the eye axis direction. grow later, thereby deepening the degree. At present, one of the main ways to alleviate the development of myopia is the "defocus lens". The central area has a normal power, and the peripheral area is adjusted through optical design partitions, so that the image in the peripheral area falls in front of the retina.

How to locate Apple wireless earphones if they are lost_How to locate Apple wireless earphones How to locate Apple wireless earphones if they are lost_How to locate Apple wireless earphones Mar 23, 2024 am 08:21 AM

1. First, we open the [Search] App on the mobile phone and select the device in the list on the device interface. 2. Then, you can check the location and click on the route to navigate there.

How to design the end page of ppt to be attractive enough How to design the end page of ppt to be attractive enough Mar 20, 2024 pm 12:30 PM

At work, ppt is an office software often used by professionals. A complete ppt must have a good ending page. Different professional requirements give different ppt production characteristics. Regarding the production of the end page, how can we design it more attractively? Let’s take a look at how to design the end page of ppt! The design of the ppt end page can be adjusted in terms of text and animation, and you can choose a simple or dazzling style according to your needs. Next, we will focus on how to use innovative expression methods to create a ppt end page that meets the requirements. So let’s start today’s tutorial. 1. For the production of the end page, any text in the picture can be used. The important thing about the end page is that it means that my presentation is over. 2. In addition to these words,

See all articles