search
HomeWeb Front-endHTML TutorialConcise CSS properties: positioning_html/css_WEB-ITnose

/* 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
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
Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

See all articles

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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft