Nice design.
Well, that’s why I will first say that, in my opinion, the solution to your bundle problem, as others have already pointed out, moves this field outside the parent (card).
But you set some limits, so I will try to break as little as possible. I do not know how to do this without violating any restrictions. Z-index is inherited (again, others pointed it out), so you cannot break out of your parents' layer only with this tool.
So, here you can get the same effect using javascript. This is ugly and may cause you more headaches later, but this should at least work:
- Find the absolute position of the div that you want to place on top.
- Make a copy.
- Hide the original (optional if it is opaque).
- Paste a copy on top of everything.
If you use jQuery, you can get the position of the element relative to the document using the .offset() function. After that, it's pretty simple:
$(document).ready( function() { $("a[href='#overlay']").click( function() { // 1: get the position pos = $('.wrap').offset(); // 2: make a copy halecopy = $('.bottom .wrap').clone(); // 3: hide the original $('.bottom .wrap').css({opacity: 0}); // 4: Insert new label on top of everything $('body').prepend(halecopy); // position the new label correctly halecopy.css({position:'absolute', top: pos.top, left: pos.left, 'z-index': 2}); // show the "top" layer $('.top').fadeIn(); }); $("a[href='#hide']").click( function() { $('.top').fadeOut( function() { // remove the label copy halecopy.remove(); // show the original again $('.bottom .wrap').css({opacity: 1}); }); }); });
This script works for me on this markup:
<div class="top"> <div class="label"> <p>Whatever</p> </div> </div> <div class="bottom"> <div class="wrap"> <div class="label"> <p>Haaaleluuuuia!</p> </div> </div> </div> <a href="#overlay">show</a> <a href="#hide">hide</a>
With these styles:
.top, .bottom { position: absolute; top: 10%; left: 3%; } .top { z-index: 1; padding: 2%; background: rgba(0, 127, 127, 0.8); display:none; } .bottom { z-index: -1; padding: 3%; background: rgba(127, 127, 0, 0.8); } .label { color: #fff; } .wrap { outline: 1px dashed rgba(127, 0, 0, 0.8); background: rgba(127, 127, 127, 0.8); } .bottom .label { z-index: 10; }
And here is a manual jsfiddle demonstration .