CSS Layout - position PropertyThe position attribute specifies the type of positioning method (static, relative, fixed, absolute, or sticky) to be applied to an element. The position property The position attribute specifies the type of positioning method to be applied to an element. There are five different position values:
Elements are actually positioned using the top, bottom, left, and right attributes. However, these properties have no effect unless the position property is set first. They work differently depending on the position value. CSS Layout - Floating and Clearing float property The float property can be set to one of the following values: left - the element floats to the left side of its container float: left|right; can automatically arrange and wrap lines, but requires clear to clear the float; display: inline-block can sometimes replace float to achieve the same effect. position: absolute|relative; To coordinate with top, left and other positioning; use: position: The difference between CSS layout float and positioning attributesCSS has three basic positioning mechanisms: normal flow, floating and absolute positioning. 1. Normal flow The position of the element box in the normal flow is determined by the position of the element in XHTML. Block-level elements are arranged from top to bottom, and the vertical distance between boxes is calculated by the vertical margin of the box. Inline elements are laid out horizontally in a row. Normal flow is the elements in the HTML document, such as block-level elements and inline elements, according to their display attributes in the document. Position:relative is the relative positioning of child block-level elements to the parent element. The positioning keywords use left/right/top/bottom. Sibling block elements are positioned relative to each other, but after the position is moved, the original position is still retained. And the subsequent positioning of sibling block elements is based on the position before being moved. float:right/left is the positioning of the sub-block-level element flow set towards the parent element, and the keywords used for positioning are margin/padding. The relative positioning between sibling block elements is re-rendered based on the new position after the move. They can overlap and the original position is cleared. The biggest difference between the two is position retention. People use this difference to create a sliding door menu using CSS code. 123WORDPRESS.COM Editor AddedGenerally, float is used for page layout, but you need to pay attention to clearing the float. Some special effects generally use position. Elements using position can appear anywhere on the page, which is convenient for some prompt boxes, special effects, etc. Specifically, you can click F12 on the page you see and study it slowly, and you will find a lot of fun. |
<<: Detailed explanation of how to dynamically set the browser title in Vue
>>: The difference between HTML name id and class_PowerNode Java Academy
<br />Adding pictures reasonably can make a ...
2.1 Semanticization makes your web pages better u...
Table of contents 1. Background 2. Prerequisites ...
Preface The count function is used to count the r...
Sometimes we need to remotely run programs on the...
1. DNS server concept Communication on the Intern...
Today I found this prompt when I was running and ...
<br />This web page production skills tutori...
Port Mapping Before the Docker container is start...
I just bought an Alibaba Cloud host and couldn’t ...
1. DOCTYPE is indispensable. The browser determin...
Prepare Environmental information for this articl...
Table of contents Objectives for this period 1. F...
In the previous article https://www.jb51.net/arti...
Table of contents Preface text 1. Closure 1.1 Wha...