Home Web Front-end HTML Tutorial Concise CSS properties: positioning_html/css_WEB-ITnose

Concise CSS properties: positioning_html/css_WEB-ITnose

Jun 24, 2016 pm 12:33 PM

/* Extremely simple, seniors please ignore it*/

Chapter 1 Positioning (Positioning)

Keywords: position/z-index/top/bottom /right/left/clip

POSITION

This attribute is used to determine the position of the element on the page. Usage: position: static (default) | fixed | relative | absolute

static

Follow the normal document flow and do not set the top, bottom, left, and right values.

fixed

It is separated from the normal document flow, completely based on the browser window, and does not scroll with the scrolling of the mouse. Set the tblr value.

relative

Relative to what? Is offset relative to the element's original position in the document flow.

That is to say, if it should be at A according to the document flow, the relative attribute and left=10px are set;

Then the final position is: A is offset to the right by 10px.

Of course the size of this element will not change, thus causing it to cover other boxes.

Application: Elements with relative positioning values ​​are usually used as parent containers of elements with absolute positioning values.

absolute

Why is it called absolute? Because the element needs to be positioned, it must "absolutely" be searched from the inside to the outside of the container, looking for the element with the position attribute set (the default value of static is not counted). In other words, if X is set to absolute positioning, when positioning, it depends on whether the parent Y of Continue to see if Y's parent Z has a position set... If not, use the html element as the basis for positioning. The element breaks away from the normal document flow. Hence causing other boxes to be covered.

Application: By simply setting the absolute positioning attribute, the element can be positioned to any part of the web page. (Of course, it’s good to use the relative parent as a benchmark)

Okay. After introducing several position values, the word coverage was mentioned several times above.

So how to decide who goes up and who goes down when elements overlap? Here the z-index attribute is introduced.

Z-INDEX

By assigning a value to the z-index of each element, comparisons are made when overlapping, with the larger one at the top and the smaller one at the bottom. Usage: z-index: auto (default) | positive/negative value | inherit Usage: can only be used to position elements (that is, the position attribute value is set)

auto

Default value, with its parent The elements are consistent.

inherit

explicitly states that it must be inherited from the parent element.

Note: If the index values ​​are the same, the stacking order will be determined based on the order in which they appear in the document flow, with the later ones taking precedence.

Then there are top/bottom/left/right.

top/bottom/left/right

Set the offset. Usage: top: auto (default) |value|percentage Usage: only for positioned elements.

The value is expressed directly in px, etc. The percentage is relative to the parent container.

For example, if the left=50% of positioned element

clip

is used to clip elements (not limited to images). Usage: clip: auto (default) | rect (top, right, bottom, left) Usage: only used for elements with attributes position:absolute && overflow != visible.

auto does not crop

The four parameters in rect are pixel values. All four values ​​are relative to the (0,0) point in the upper left corner of the image.

For example, if the original width of the image is 100px and right=10px is set in rect, then after cropping, the width of the image will be 10px. The right margin has been moved 90px to the left.

--------------------------------------------- ----------------

Positioning ends here.

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

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

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