How to define CSS layering order?

50 views Asked by At

order

How can I put box1 behind box2?

expected order

<div class="box2">username</div> -> position: fixed; 
<div class="box1">logo</div> -> position:relative;
3

There are 3 answers

0
Jay On

This should work:

.box1{z-index:1}
.box2{z-index:2}
0
Vaibhav Jain On

Try using z-index property.

The z-index property specifies the stack order of an element.

An element with greater stack order is always in front of an element with a lower stack order.

Note: z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).

Refer following :

0
Dheeraj On

You have to define "TOP" position

.box2 {position: fixed;  top: 0; }