Reputation: 73
I am setting up an interface for a social network, however, I am having an issue with z-index in google chrome. It seems to work as expected in safari, firefox and internet explorer.
See my layout on the jsfiddle: http://jsfiddle.net/KV5nw/1/
The side bar should be fixed to the left of screen and the grey avatar should be above the dark grey block at the top.
If #sidebar has position fixed applied then #user_avatar's z-index is ignored. If you set #sidebar's position to relative or absolute then #user_avatar's z-index is fine.
#sidebar{
width:inherit;
position: fixed;
display: block;
}
#user_avatar{
margin:0 auto;
width:120px;
height: 120px;
border:4px solid white;
background-color: #555;
display: block;
margin-top:-100px;
position: relative;
z-index:501;
}
I am on google chrome version: Version 32.0.1700.107
Any advice?
Upvotes: 4
Views: 18796
Reputation: 1
Set the z-index for the fixed element too. I mean:
#sidebar{
width:inherit;
position: fixed;
display: block;
z-index: 501;
}
Upvotes: 0
Reputation: 1
I solve a similar probleme by changing the position on sideBar from fixed to absolute
Upvotes: -1
Reputation: 5444
The problem is that Chrome creates a new stacking context for elements that don't have a z-index
set (default is auto). So your sidebar has a z-index
of 0 which makes it (and all of its childrens) disappear since you've specified a higher z-index for your #top
container.
To solve the problem, give the sidebar a z-index
higher than the one from #top
:
#sidebar{
width:inherit;
position: fixed;
display: block;
z-index: 501;
}
Upvotes: 5
Reputation: 2874
#user_avatar
and #top
must be place at one level on DOM for normal z-index
. Now parent of #user_avatar
(#sidebar
) has z-index:0
and z-index of #user_avatar
working only inside #sidebar
. Add to parent of #user_avatar
(#sidebar
) z-index:501
or replace #user_avatar
Upvotes: 0