css中的z-index_html/css_WEB-ITnose
Z-index
在我们常用的css中z-index 属性是设置节点的堆叠顺序, 这是我们对 z-index 属性普遍的认识. 与此同时, 我们总是对堆叠顺序的概念模糊不清,这样将会导致我们在平时的布局中出现一些问题。下面我个人对css中z-index的一些个人的认识,希望能帮到大家,有说错的地方希望大家指正。
css布局中我们常常会使用一些float:laft;和float:right;以及定位中的absolute,relative,fixed;
有的人误认为定位和定位之间是本身就存在附带堆叠顺序的,在自己经过测试之后发现,他们的默认是没有堆叠顺序的,只是在html中标签的前后顺序导致的而使大家误认为是定位和定位之间的堆叠顺序而导致的。
下面是正常使用z-index代码示例:
定位中的static是标准流,所以这里不做讲解
当我们有三个盒子
div { width: 100px; height: 100px; color: white; float: left; }.div1 { position: fixed; background-color: red; }.div2 { background-color: blue; position: relative; }.div3 { background-color: green; position: absolute; } </style></head><body><div class="div1">div1</div><div class="div2">div2</div><div class="div3">div3</div></body></html>
我们给他们分别设置fixed,relative,absolute;背景色为红色,蓝色,绿色
我们会发现absolute的绿色盒子会在最上面,在html代码中更改标签的位置顺序则可以让盒子出现在堆叠层的最上面,当然如果我们要想在不改变html标签的顺序,那么我们就可以使用第二种方法z-index:
在我们添加z-index是要注意这个样式是有值的;值也可以影响我们的堆叠顺序。
样式内z-index的值越大的堆叠层越高,当然我们也要注意z-index也并不是在什么时候都管用的。
只有在同一样式时,比如定位与定位之间的堆叠,浮动与浮动之间的堆叠,如果有两个盒子,一个盒子为浮动元素一个盒子为定位元素,两个盒子发生堆叠,此时我们想要浮动的盒子显示在定位盒子之上,我们是没有办法的,设置z-index这个时候是没有用的。
定位的盒子本身堆叠的顺序就要比浮动的盒子的堆叠顺序要高,所以此时我们要解决这个问题就需要把浮动盒子换成定位的盒子,设置之后我们就可以z-index来设置堆叠顺序了。
上面是本人的一点个人观点,希望可以帮到大家,后续自己也会写一些关于web中一些个人认识。有不同观点大家可以随意发表。

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

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.

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.

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

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...
