Explain this modal behavior with z-index and position? - css

I actually solved this issue for myself but was wondering if anyone could explain why my fix works. I was styling a popup modal on a mobile site using the MoovWeb SDK and sass. The modal consists of a mask div, which is located immediately inside a container div, and the modal div itself, which was buried more deeply in the DOM.
mask styling:
#modalMask{
opacity: .8;
position: absolute;
display:none;
height:100%;
width: 100%;
z-index:9990;
}
modal styling:
.mw-popup-modal {
top: 80px !important;
left: 0 !important;
position:fixed;
z-index:9999;
display:none;
}
This resulted in the mask sitting on top of the modal and the buttons inside the modal being un-tappable - their tap area was actually located around 3cm below where the button was appearing onscreen on the phone. However, on the desktop version of the site, this styling looked fine.
When I changed the positioning of the modal from "fixed" to "absolute" this fixed the problem, but I'd like to understand why. Do fixed- and absolute-positioned elements each work on their own z-index stack?

Official W3 documentation states
Fixed positioning is a subcategory of absolute positioning. The only difference is that for a fixed positioned box, the containing block is established by the viewport. For continuous media, fixed boxes do not move when the document is scrolled. In this respect, they are similar to fixed background images.
Absolute and Fixed positioning do not work on their own z-index stack context.

Related

Position:fixed div touch area shifts up while scrolling down on chrome mobile

I have div with the id #sy-whatshelp for a floating chat head which has the property Position:fixed as I want it fixed on the bottom right corner of the viewport. The css for the div is
#sy-whatshelp {
right: 15px;
bottom: 15px;
position: fixed;
z-index: 9999;
}
The issue is that in chrome mobile browser when scrolling down very fast, the touch area of the div shifts up even though visually the div stays in the correct position as defined by my css. How do I make the touch area of the div stick to the correct place too as defined by my css.
Here is a video link of the problem in chrome mobile dubugger connected to a pc using adb. You can see that the highlighted portion identifying the div goes up while scrolling down but visually its in the correct place.
https://imgur.com/a/yJBUMdR
I have tried this solution with no avail
Position fixed on chrome mobile causing element to move on scroll up/down

Cant figure out stacking order issue on Chrome

My collapsed dropdown menus are being hidden behind a sequence.js slider on Chrome and Safari. Issue doesn't appear to be happening on Firefox. Tried changing z-index on just about every object related to slider and menu. Much love to anyone who can inspect my site and tell me what I am doing wrong.
https://www.shopinspired.co/
It's not actually being hidden behind the slideshow.
This is due to the "sticky" class being removed from your header when you scroll to the top of the page. If #header always has .sticky, the menu shows fine.
It looks like your styles at the top of the page are targeting "header.sticky", not just "header".
Fix: Manually add the css:
#header {
position: fixed;
left: 0;
right: 0;
top: 0px;
box-shadow: 0 5px 5px -5px #333;
}
or change the CSS in the page head to target "header".
Explanation
Its is coming from the sticky header and a mismatch of positioned objects and forced heights.
By default, without the sticky header, the submenu is being hidden because it is a child element of a parent with a forced height due to some media queries. The overflow is being hidden.
When the sticky header is added, the header gets a position of fixed. You can not use absolute positioning relative to fixed elements. I am guessing your element is being positioned relative to the document window which is why it is now showing with the fixed attribute.

Absolute positioned div with dynamic height

I have a site based on foundation 5 & angularjs with the following layout:
header
-left-nav
--content
footer
Currently the left nav is absolute positioned to the left with an initial height of 100% (top:0, bottom:0)
The content div changes in height as to what is being loaded into it (via ajax). I'm manually adjusting the height of the left-nav div when the content height changes, but I was wondering if there was a way with html/css that would enable me to get rid of this script.
I've tried using all the techniques i've found through googling, but none seem to work without the javascript.. I need the left nav to always been 100% of the page height as it has a dark background that stretches to the bottom of the page.
Many thanks,
Ben
Update
Its working in this jsfiddle.net
This FIDDLE has an "add content" button which will show you it working with dynamic data.
I just changed this ...
.small-fixed-130-left.column {
position:absolute;
width:11.4285714286rem;
top:0;
left:0;
bottom: 0;
}
You could position: fixed; the left nav with a height: 100%;

Centering a Modal for IE9 with a transparent background, why need position relative?

The back story....
I'm creating a modal directive for AngularJS that should take any** content and display it centered in the page with a grey transparent background. Sounds like it should be simple. It was working fine until testing w/ IE9 which is the only browser we need to support. Its an in-house site. I have a fiddler working with it centered both vertically and horizontally, that probably could be cleaned up a little. I'm assuming that its going to work, I'm on a mac right now.
The modal's html needs to be in the footer which is fixed to the bottom of the page. So
So I have two questions.
1st- When I was setting up the grey transparent background found that I needed so set the position as relative. Why is this needed? fiddler
.dialogbox-wrapper{
z-index:1000;
display: table-cell;
vertical-align: middle;
/* When this isnt included this has the opacity */
position:relative;
}
2nd- We are using less and CSS3. Is there a cleaner way?
Here's what I need -
Before anyone suggests !doctype HTML, its there.
As to #1
For z-index to be honored, an element must have position of some kind. If position: relative is simply removed, then the default static position does not recognize the z-index: 1000 and so the gray box's z-index: 50 puts your "background" to the foreground.
As to #2
"Cleaner" can be so relative. Here is a modified version of your fiddle that centers it without the need for the min-width (which you expressed in your notations wanting to eliminate), by using display: inline-block with the container set to text-align: center (which is reset on the element itself). It also sets the <a> element for the "close" to display: block so that your width: 200px actually does something (an anchor is an inline element normally, which does not honor width). Of course, now 200px for the .row is driving the width of the modal display.
It all works in IE9 for me.

CSS IE7 bug - z-index or other property affecting my absolute div, which is being blocked by other positioned divs below

The header of my site has a button which, when clicked, should bring up a popup, with a form inside, (just below the button) allowing customers to search the site.
My Jquery code to do this:
<script type='text/javascript'>
$(document).ready(function () {
$('#search-my-size-inner').click(function() {
$('#search-my-size-lightbox').toggle();
$("#search-my-size-lightbox").css("z-index","1000");
});
});
</script>
My div, search-my-size-lightbox, has the following CSS.
.lightbox-search-my-size { color: #673645; opacity: 0.9; filter:alpha(opacity=90); background: #fff; }
#search-my-size-lightbox { position: absolute; width:390px; right: 0; top: 26px; display: none; }
And the div is:
<div id='search-my-size-lightbox' class='lightbox-search-my-size'>my content </div>
This works fine on all browsers except IE7. The 'z-index' is unnecessary since I can do that from CSS, but it was worth a try for IE7 but still did not fix the bug.
The bug is that the div is "hidden" (or blocked) by several other absolute and relative elements below. If I move the div way down to before the "/body" tag, then the div shows. However, I need it up in the code within its parent "relative" tag to position is correctly.
The div shows fine over normal content, it is just that there are some big home page banners below the header, with several relative and absolute divs, which block the popup content. If I remove those "position" attributes, then the popup shows fine, but of course the home page banners' layout is messed up so this is not a solution.
Also, if I change #search-my-size-lightbox to position: relative, then it will work, but this simply pushes content down, and I need an absolute, popup-like div.
The following looks useful but doesn't seem to work for me:
1. Positioning divs with z-Index in Internet Explorer 7
2. http://www.sitepoint.com/fix-disappearing-absolute-position-element-ie/
3. IE7 relative/absolute positioning bug with dynamically modified page content
Any advice would be appreciated,
Many thanks!
The problem seems to be related to the stacking context. The z-index property only affects the stacking order of the children in a single parent, not to elements with different parents. See the "Understanding z-index and stacking contexts" section of the YUI Overlay documentation for more information about this.

Resources