Here is my tooltip:
.tooltip-content{
visibility: hidden;
min-width: 180px;
background-color: rgba(38, 38, 38, 0.9);
color: #fff;
text-align: center;
border-radius: 4px;
padding: 5px 3px;
position: absolute;
font-size: 0.8em;
z-index: 5;
top: 120%;
left: 50%;
transform: translateX(-50%);
}
.tooltip-content::after {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
z-index: 5;
border-style: solid;
border-color: transparent transparent rgba(38, 38, 38, 0.9) transparent;
}
.btn-tag:hover .tooltip-content {
visibility: visible;
z-index: 5;
}
And here is the parent block
.btn-tag {
position: relative;
border: 1px solid #333;
border-radius: 4px 4px 4px 4px;
color: #333;
font-weight: 500;
padding: 0.7em 0.4em;
font-size: 1em;
text-align: center;
width: 100px;
z-index: 1;
cursor: pointer;
background: red;
}
The problem is when I hover over a Block A the tooltip is being hidden under a Block B even though its z-index value is higher.
DEMO
What am I doing wrong and how can I fix it?
Each z-index declaration establishes a local stacking context. So by specifying z-index: 1 on the .btn-tag, you're establishing a local context for each button for the descendant z-index (the tooltip has a higher z-index "inside" the context of the parent, the first btn-tag, but then the second btn-tag has another context with the same z-index value and since it's after on the DOM it appears on top).
If you were to remove the z-index rule on the .btn-tagclass leaving it by default, then it will behave as you require it.
Please find the demo: https://jsfiddle.net/y6udf6f8/
Related
I created this Tooltip element using HTML and CSS. But after a while I realized that the pointer of my tooltip is getting cut. At first I thought it was some overflow issue but it wasn't. Then I tried to change the zoom level of my chrome and I got this
ZOOM LEVEL <= 250%
As you can see the pointer of the tooltip (highlighted in red) is getting cut.
ZOOM LEVEL => 250%
Now, as you can see the same tooltip on different zoom level worked or rendered just fine.
Anyone can tell me what is the actual problem behind all this or this is a browser issue??
CODE FOR TOOLTIP
<div class="tooltip">
<div class="tooltip-pointer" data-pointer-direction="bottom"></div>
<div class="tooltip-content">Hello, World!</div>
</div>
.tooltip {
position: absolute;
color: white;
max-width: 196px;
font-weight: 600;
user-select: none;
border-radius: 4px;
font-size: 0.875rem;
pointer-events: none;
word-wrap: break-word;
transform-origin: 50% 0;
letter-spacing: 0.03125rem;
background-color: #18191c;
will-change: opacity, transform;
box-shadow: 0 5.18px 10.36px -3.89px rgba(0, 0, 0, 0.25);
.tooltip-pointer {
width: 0;
height: 0;
position: absolute;
pointer-events: none;
border: 5px solid transparent;
border-top-color: #18191c;
&[data-pointer-direction='bottom'] {
top: 100%;
left: 50%;
margin-left: -5px;
}
}
}
UPDATE
I haven't found any solution though instead what I did I change the pointer of tooltips from HTML to SVG after doing this the tooltip arrows or pointers is not getting cut on different zoom level or any zoom level. If anyone want the code DM me.
Why don't you try creating the down arrow in a different way? Something like this: https://jsfiddle.net/2jwhnrm3/
HTML
<div class="tooltip-pointer"></div>
<div class="tooltip">
<div class="tooltip-content">Hello, World!</div>
</div>
CSS
.tooltip {
position: absolute;
color: white;
max-width: 196px;
font-weight: 600;
user-select: none;
border-radius: 4px;
font-size: 0.875rem;
pointer-events: none;
word-wrap: break-word;
transform-origin: 50% 0;
letter-spacing: 0.03125rem;
background-color: #18191c;
will-change: opacity, transform;
box-shadow: 0 5.18px 10.36px -3.89px rgba(0, 0, 0, 0.25);
}
.tooltip-pointer {
border: solid red;
background: red;
border-width: 0 3px 3px 0;
display: inline-block;
position: absolute;
padding: 5px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
top: 17px;
left: 50px;
margin-left: -5px;
}
I am making a section which contains price info section and order now button.
Here, there is a wrapper border class that make the border for the entire section.
Scenario:
In this case consider that button is disabled with opacity and hence it looks like this now.
.border {
border: 4px solid rgb(195, 0, 38);
border-bottom: transparent;
}
.info-card {
padding-bottom: 20px;
}
button {
background-color: rgb(195, 0, 38);
opacity: 0.5;
border-radius: 10px;
color: #fff;
padding: 5px;
}
.order-button {
margin-top: -1.5rem;
}
<div class="border">
<div class="info-card">
<h1> Info Section </h1>
</div>
</div>
<div class="order-button">
<button>
Order Now
</button>
</div>
But the requirement is that the border line should go behind the button (and not above the button) as like the below image.
Expected Result:
Note: Here opacity is included to make the button look like disabled.
Also the color given above varies and so please don't include any other addition of colors.
Tried with increasing z-index of button but that doesn't work in this case.
Try this:
button::after {
position: absolute;
content: "";
width: 100%;
height: 100%;
left: 0;
border-radius: 20px;
background-color: rgba(197, 218, 227,.5);
top: 0;
z-index: 9999;
}
button {
background-color: rgb(197, 218, 227);
border-radius: 37px;
color: #fff;
padding: 12px 5px;
display: block;
width: calc(100% + 4px);
margin-left: -2px;
margin-right: -2px;
border: unset;
cursor: pointer;
position: relative;
}
I have this test setup. When I hover over the "Block 1" it should get transformed while keeping its integrity. What I see is that background color is changing. It seems like it's all about background of that .blocks:after element.
(if I comment that, background of element won't change while hovering over).
So, what could cause a problem?
Source - https://jsfiddle.net/1k5e2090/6/
body {
background: #d3d3d3;
}
.blocks {
display: flex;
position: relative;
width: 150px;
height: 55px;
margin: 25px;
justify-content: center;
align-items: center;
color: white;
font-family: 'Helvetica', sans-serif;
font-size: 20px;
}
.blocks#block1 {
background: #4BACC6;
left: 500px;
top: 200px;
}
.blocks#block2 {
left: 500px;
top: -50px;
background: #9BBB59;
}
.blocks#block3 {
left: 200px;
top: -45px;
background: #C0504D;
}
.blocks:after {
position: absolute;
content: '';
background: #F2F2F2;
top: -7px;
left: -7px;
right: -7px;
bottom: -7px;
z-index: -1;
}
.blocks#block1:after {
box-shadow: 3.5px 5.5px 1px -1px rgba(75, 172, 198, 0.45);
}
.blocks#block2:after {
box-shadow: 3.5px 5.5px 1px -1px rgba(155, 187, 89, 0.45);
}
.blocks#block3:after {
box-shadow: 3.5px 5.5px 1px -1px rgba(192, 80, 77, 0.45);
}
.blocks#block1:hover {
transition: 1s ease;
transform: translate(-100px);
}
It's because of the :after behavior on .blocks elements. See this fiddle
.blocks:hover:after { border: 6px solid #fff; background: transparent; z-index: -2; }
.blocks {
border: 7px solid #f2f2f2;
}
i have edited your fiddle https://jsfiddle.net/1k5e2090/9/
you have used the border as a :pseudo element which is not necessary. it is actually creating the problem
In place of using before and after use simple border on blocks and gives box shadow, This is happened because you use position absolute in before and after so when a block moves before and after adopt automatically.Hope it work
Simple use border around the block and remove before and after your problem will solved
I have a dialogue box or a arrow box which should be set to max height of 60%, and all the content inside the box overflows via scroll, this is the markup:
<div class="cart">
hello world
</div>
and here is the css to make a arrow-head on top:
.cart {
position: fixed;
background: #ffffff;
opacity: 1;
box-shadow: 1px 1px 10px;
border-radius: 5px;
margin-left: 74.8%;
width: 300px;
top: 70px;
padding: 13px;
z-index: 20;
text-align: center;
display: none;
max-height: 60%;
overflow: auto;
}
.cart:after, .cart:before {
top: -20px;
bottom: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.cart:after {
border-color: rgba(255, 255, 255, 0);
border-bottom-color: #ffffff;
border-width: 10px;
margin-left: -10px;
}
.cart:before {
border-color: rgba(12, 143, 176, 0);
border-bottom-color: #999;
border-width: 11px;
margin-left: -11px;
}
if I remove the "overflow" property the arrow head shows up, but when I use it, which I have to It disappears, I want both, an arrow head and scrollable div, but I think the arrowhead just gets inside the scroll. is there any solution for this?
Thanks for the help
I'm trying to place the :before,:after box-shadow behind the button. But the transition is starting in front of the a tag. For my works CMS, I'll need all the properties to be on the a tag.
Join Today
.btn{
position: relative;
z-index: 1;
display: inline-block;
text-align: center;
background-color: #8ec656;
border-radius: 30px;
font-family: 'Roboto Condensed', sans-serif;
font-size: 20px;
color: #fff;
border: 3px #d2d2d2 solid;
padding: 15px 40px;
line-height: 1;
transition: box-shadow .4s;
}
.btn:hover{
background: #6b9640;
box-shadow: inset 0px -22px 13px 0px #84b652, inset 0px 2px 5px 0px #84b652;
}
.btn:before,
.btn:after{
content: "";
position: absolute;
z-index: -1;
bottom: 9px;
left: 10px;
width: 88%;
top: 73%;
transition: box-shadow .4s;
}
.btn:hover:before,
.btn:hover:after{
box-shadow: 0 15px 10px #777;
}
https://jsfiddle.net/3aj5muyu/
That's because .btn establishes a stacking context, so its background will always be at the back of its contents. The back-to-front order is
the background and borders of the element forming the stacking context.
the child stacking contexts with negative stack levels (most negative first).
the in-flow, non-inline-level, non-positioned descendants.
the non-positioned floats.
the in-flow, inline-level, non-positioned descendants, including inline tables and inline blocks.
the child stacking contexts with stack level 0 and the positioned descendants with stack level 0.
the child stacking contexts with positive stack levels (least positive first).
To fix it, .btn shouldn't establish a stacking context. Move the following properties to a wrapper:
position: relative;
z-index: 1;
.btn-wrapper {
position: relative;
z-index: 1;
display: inline-block;
}
.btn{
display: inline-block;
text-align: center;
background-color: #8ec656;
border-radius: 30px;
font-family: 'Roboto Condensed', sans-serif;
font-size: 20px;
color: #fff;
border: 3px #d2d2d2 solid;
padding: 15px 40px;
line-height: 1;
transition: box-shadow .4s;
text-decoration: none;
}
.btn:hover{
background: #6b9640;
box-shadow: inset 0px -22px 13px 0px #84b652, inset 0px 2px 5px 0px #84b652;
}
.btn:before,
.btn:after{
content: "";
position: absolute;
z-index: -1;
bottom: 9px;
left: 10px;
width: 88%;
top: 73%;
transition: box-shadow .4s;
}
.btn:hover:before,
.btn:hover:after{
box-shadow: 0 15px 10px #777;
}
<div class="btn-wrapper">
Join Today
</div>
.btn:before,
.btn:after{
transition: .6s;
content: "";
box-shadow: 0 28px 17px -3px #777;
width: 84%;
height: 11px;
top: 48%;
left: 15px;
position: absolute;
opacity: 0;
}
.btn:hover:before,
.btn:hover:after{
opacity: 1;
}
This is what I had to settle with. Thank you for your responses!
Take a look at this working example:
.btn {
position: relative;
/* z-index: 1; */
display: inline-block;
background-color: #8ec656;
border-radius: 30px;
border: 3px #d2d2d2 solid;
padding: 15px 40px;
transition: box-shadow .4s;
text-decoration: none;
}
.btn > span {
text-align: center;
font-family: 'Roboto Condensed', sans-serif;
font-size: 20px;
color: #fff;
line-height: 1;
}
.btn:hover{
background: #6b9640;
box-shadow: inset 0px -22px 13px 0px #84b652, inset 0px 2px 5px 0px #84b652;
}
.btn:before,
.btn:after{
display: inline-block;
content: "";
position: absolute;
z-index: -1;
bottom: 9px;
left: 10px;
width: 88%;
top: 73%;
transition: box-shadow .4s;
}
.btn:hover:before,
.btn:hover:after{
box-shadow: 0 15px 10px #777;
}
<span>Join Today</span>
https://jsfiddle.net/7argwcje/
That's because before and after elements are effectively children of the .btn element and siblings of the plain text (Join today). So you have no way to force the text to be on front.
These are the changes:
.btn {
position: relative;
/* z-index: 1; */
display: inline-block;
background-color: #8ec656;
border-radius: 30px;
border: 3px #d2d2d2 solid;
padding: 15px 40px;
transition: box-shadow .4s;
text-decoration: none;
}
.btn > span {
text-align: center;
font-family: 'Roboto Condensed', sans-serif;
font-size: 20px;
color: #fff;
line-height: 1;
}
Basically transferred some properties from .btn to a wrapper span element.
Notice that the z-indexes are no longer necessary.