Fixed position and z-index

Yes, those fixed-positioned elements are annoying; please bear with me.

The two fixed-position divs on this page are marked up as:

<div class="fixed" id="green"></div>
<div class="fixed" id="orange"></div>

and styled thus:

.fixed { width: 50%; margin: 0 auto; height: 50px;
    position: fixed; }

#green  { top: 50px; background-color: #CEE14B; }
#orange { top: 110px; background-color: #FCAF3E; z-index: 1; }

Note that the lower, orange element has a z-index specified, whilst the first element doesn’t. The ul just below this text has a relative position. When the page is scrolled, and the orange div overlaps that list, all looks fine. When the green div overlaps it, however, the list items are shown in front of it.

Is this a bug, or expected behaviour? I’m really not sure. Comments, please!


Tweet

Comments

Sat 28 Nov 2009 09:57

Danny

Danny said:

expected behavior…

Since the green DIV has no z-index priority… it is on the same plane as every other non z-indexed element on the page. The indexing now falls to where it’s placed in the code. Since it’s before the UL list… it has a lower indexing on that plane… If you place the green DIV after the UL list… you'll see that it now goes over the UL list… thus having a higher indexing on that plane…

Fri 22 Jan 2010 12:30

raf

raf said:

Sounds plausible and works as you described, Danny. But how come the paragraph following the list, "Is this a bug…", does not behave the same way? Why does this behaviour only apply to the list?

Sun 24 Jan 2010 11:27

Five Minute Argument

Five Minute Argument said:

@raf: That paragraph is not positioned, so it’s in the normal flow. With no z-index (and, therefore, the deafult value 'auto'), the positioned green div will be rendered 'in front of' any normal-flow block.

z-index gets pretty complicated, especially when nesting blocks or applying a negative value to the property. I think a nice visual example covering the possible cases is called for.

Mon 2 May 2011 13:02

said:

Thanks, you saved my time.

Wed 24 Aug 2011 03:21

Simon Brandon

Simon Brandon said:

You are an absolute star — I've been pulling my hair out trying to get a div to go above a fixed position div for ages, messing around with z-index without success. Just set the div in question to position:relative and it happily slides over the position:fixed div.

Thu 13 Oct 2011 13:44

Jonathan Gala

Jonathan Gala said:

Nice illustration, thanks.

Simon and Five Minute Argument: there is a nice tutorial on z-index (and some bugs in earlier IE implementations) here:

http://aplus.rs/lab/z-pos/

… that’s not my site, btw, but it’s a good overview, with nicely prepared examples. It helped my understanding of z-index a lot.

Wed 14 Dec 2011 01:21

Jim

Jim said:

Thanks for raising this issue along with an example — and thanks a lot Danny for answering it. Perfect!

Regards,

Jim

Sat 13 Dec 2014 12:11

non prescription cialis online pharmacy

non prescription cialis online pharmacy said:

Hi there, I enjoy reading all of your post. I like to write a

little comment to support you.

Mon 15 Dec 2014 21:23

generic cialis canada

generic cialis canada said:

Your means of explaining all in this post is genuinely good, all be capable

of effortlessly understand it, Thanks a lot.

Fri 19 Dec 2014 01:46

north west pharmacy canada

north west pharmacy canada said:

WOW just what I was looking for. Came here by searching for canadian prescription drugs

without prescription

Sat 20 Dec 2014 09:41

canadian cialis pills

canadian cialis pills said:

Thanks for the auspicious writeup. It actually was a leisure account it.

Glance advanced to far delivered agreeable from you!

By the way, how can we keep in touch?

Sat 20 Dec 2014 09:51

cialis 20mg

cialis 20mg said:

excellent submit, very informative. I wonder why the opposite specialists of this sector do not realize this.

You must continue your writing. I am sure, you have a great readers' base already!

Wed 24 Dec 2014 16:24

cialis com

cialis com said:

Greetings! Very helpful advice within this post!

It is the little changes that will make the biggest changes.

Many thanks for sharing!

Tue 30 Dec 2014 01:43

canadian cialis

canadian cialis said:

Hello colleagues, its great paragraph concerning tutoringand entirely defined, keep it up all the time.

Tue 30 Dec 2014 06:03

goodrx coupons

goodrx coupons said:

Hi there, I found your site via Google even as searching for

a comparable topic, your web site came up, it appears good.

I've bookmarked it in my google bookmarks.

Hi there, just was aware of your weblog thru Google, and located

that it is truly informative. I’m going to be careful for brussels.

I will be grateful if you happen to continue this in future.

Numerous other folks can be benefited from

your writing. Cheers!

Tue 30 Dec 2014 06:46

canada pharmacy online viagra

canada pharmacy online viagra said:

I loved as much as you will receive carried out right here.

The sketch is attractive, your authored

material stylish. nonetheless, you command get got an nervousness over

that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this increase.

Thu 1 Jan 2015 10:25

northwestpharmacy

northwestpharmacy said:

Hurrah, that’s what I was searching for, what a data! existing here at this webpage, thanks

admin of this web site.

Thu 8 Jan 2015 10:39

north west pharmacy canada

north west pharmacy canada said:

Hiya! Quick question that’s entirely off topic. Do you know how to make your site mobile

friendly? My blog looks weird when viewing from my iphone.

I’m trying to find a template or plugin that

might be able to fix this problem. If you have any recommendations, please share.

Thank you!

Mon 12 Jan 2015 20:49

online pharmacy cialis

online pharmacy cialis said:

Hey! I just wanted to ask if you ever have any problems with hackers?

My last blog (wordpress) was hacked and I ended up losing many months of hard work

due to no backup. Do you have any solutions to stop

hackers?

Tue 13 Jan 2015 13:25

bvhitud

bvhitud said:

inpncbjl

Wed 14 Jan 2015 07:13

cialis daily 5 mg price

cialis daily 5 mg price said:

Very nice article, totally what I needed.

Fri 16 Jan 2015 14:54

Pet medications cheap

Pet medications cheap said:

Useful information. Lucky me I discovered your website by accident,

and I am stunned why this coincidence didn’t took place earlier!

I bookmarked it.

Fri 16 Jan 2015 16:01

Cialis dreampharmaceuticals online

Cialis dreampharmaceuticals online said:

Hi! This post couldn’t be written any better! Reading through this post reminds me of my good old room mate!

He always kept chatting about this. I will forward this post to him.

Fairly certain he will have a good read. Thank you for sharing!

Sat 17 Jan 2015 11:23

Cialis paypal canada

Cialis paypal canada said:

I every time emailed this blog post page to all my contacts, because if like to

read it next my friends will too.

Sun 18 Jan 2015 09:47

hello

hello said:

yzqnzwo http://zzfcjd.com/ <a href="http://spsfqn.com/ ">pjbuqyt</a> [url=http://tehyuo.com/]pjbuqyt[/url]

Sun 18 Jan 2015 16:22

Cialis online pharmacy uk

Cialis online pharmacy uk said:

Wow, wonderful blog structure! How lengthy have you ever been blogging for?

you made blogging glance easy. The full glance of your site is great,

let alone the content material!

Tue 20 Jan 2015 01:12

payday loans

payday loans said:

byhetfz http://2012paydayloans.net/ payday loans >:]] http://paydayloansbra.com/ payday loans ZFgZOV http://paydayloansnsa.com/ payday loans >:]] http://paydayloansdpu.com/ pay day loans 9582 http://paydayloansqdq.com/ payday loans 1121 http://paydayloansdpl.com/ pay day loans 4049

Wed 21 Jan 2015 01:21

walgreens drug store

walgreens drug store said:

Great article, exactly what I needed.

Wed 21 Jan 2015 12:22

how to buy cialis in canada

how to buy cialis in canada said:

Hi it’s me, I am also visiting this web site regularly, this

site is really pleasant and the visitors are truly sharing fastidious thoughts.

Thu 22 Jan 2015 10:08

online pharmacies canada

online pharmacies canada said:

The Commonly used pharmacy is very very affordable whether you are from whichever

parts of the community. The value is affordable

for everyone and anyone; you want to drive of buying it.

At the time verdict is created, look at the best retail store.

Subsequent to purchasing the drugs, you have ingested it.

Just take the drugs with simple standard water. canadian drug

Wed 4 Feb 2015 06:07

canadian drugs

canadian drugs said:

Great goods from you, man. I have remember your stuff prior to and you’re simply too great.

I actually like what you have got right here, really like

what you’re stating and the way in which in which you assert it.

You’re making it entertaining and you continue to take care of to stay

it smart. I can’t wait to learn far more from you.

That is really a tremendous site.

Sun 15 Feb 2015 12:01

canada drugstore online

canada drugstore online said:

Hi, its nice paragraph concerning media print, we all

be familiar with media is a enormous source of information.

Tue 17 Feb 2015 22:22

payday loans

payday loans said:

tzytvzci http://paydayloansrnj.com/ payday loans 8987 http://paydayloansrni.com/ payday loans 4290 http://paydayloansrnk.com/ payday loan >:-[

Fri 20 Feb 2015 08:57

cialis from canada

cialis from canada said:

Hello i am kavin, its my first time to commenting

anyplace, when i read this article i thought i could also create comment due to this sensible piece of writing.

Sun 22 Feb 2015 13:27

walmart prescription prices

walmart prescription prices said:

This excellent website really has all the information and facts I wanted about this

subject and didn’t know who to ask.

Mon 23 Feb 2015 23:00

buy cialis online canada

buy cialis online canada said:

Nice post. I used to be checking constantly this blog and I am inspired!

Very helpful information particularly the ultimate section :) I maintain such info much.

I was looking for this particular info for a long time.

Thanks and good luck.

Wed 25 Feb 2015 18:37

payday loans

payday loans said:

twgnjcn http://paydayloansnsa.com/ payday loans >:]] http://paydayloansqdq.com/ payday loans :-O http://paydayloansrna.com/ payday loans =-] http://2012paydayloans.net/ payday loans EWTHlZ http://paydayloansbra.com/ payday loans 0956 http://paydayloansdpu.com/ payday loans 0949

Fri 27 Feb 2015 07:01

cialis line order

cialis line order said:

ncwklf http://ordercialisfff.com/ cialis line order gFhsZg http://buyviagrafff.com/ buy viagra 5363 http://genericviagrafff.com/ generic viagra qQcCm http://genericcialisfff.com/ generic cialis online :-O http://buycialisfff.com/ buy cialis :-O

Sat 28 Feb 2015 00:08

payday loans

payday loans said:

ecaxyh http://paydayloansrnq.com/ payday loans >:-[ http://paydayloansrns.com/ payday loans RVaAW http://paydayloansrnr.com/ fast payday loans OheXsV

Leave a comment