CSS showing different render behavior on different zoom level - html

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;
}

Related

Why isn't my button translating correctly in my div?

I'm new to HTML/CSS and attempting to replicate this button effect in a project of mine where the buttons are children of a div. However, whenever I do the translateY, my buttons move to the side instead. Here is the HTML and CSS; button-2 is the problematic one:
.container {
position: relative width: 600px;
height: 600px;
}
#button-1 {
position: absolute;
padding: 15px 25px;
font-size: 24px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #4CAF50;
border: ridge;
border-radius: 15px;
box-shadow: 0 9px #999;
top: 50%;
left: 25%;
}
#button-1:hover {
background-color: #3e8e41
}
#button-1:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(10px);
}
#button-2 {
position: absolute;
width: 100px;
padding: 5px 5px;
border-style: solid;
border-width: 2px;
border-radius: 10px;
border-color: darkslategray;
background-color: antiquewhite;
box-shadow: 0px 9px gray;
cursor: pointer;
top: 62%;
left: 50%;
/* if i remove this line, translation works as expected
but then the button is no longer centered horizontally
consequently, keeping the line breaks the affect
but the button can be centered horizontally
*/
transform: translate(-50%, 0);
}
#button-2:hover {
background-color: cornsilk;
}
#button-2:active {
background-color: cornsilk;
box-shadow: 0px 3px gray;
transform: translateY(5px);
}
<h2>Animated Button - "Pressed Effect"</h2>
<div class=container>
<button id="button-1">Btn1</button>
<button id="button-2">Btn2</button>
</div>
The problem seems to stem from transform: translate(-50%, 0);, which is what I have to do to center button-2 horizontally in the container div. I can remove that line and the effect works, but then button-2 is no longer centered horizontally. Why is it that transform: translate(-50%, 0); seemingly causes the subsequent transform: translateY(5px); not to work for button-2? Is there anyway I can horizontally (but not vertically) center button-2 while also being able to achieve the desired effect?
The problem is that when you set the translate property on the second button becoming active, you overwrite the original transform which is moving the button by half its width in the negative X direction.
It is important to keep this translation as well as the new one so make the translation in the active state set both the X and Y values that you want.
.container {
position: relative width: 600px;
height: 600px;
}
#button-1 {
position: absolute;
padding: 15px 25px;
font-size: 24px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #4CAF50;
border: ridge;
border-radius: 15px;
box-shadow: 0 9px #999;
top: 50%;
left: 25%;
}
#button-1:hover {
background-color: #3e8e41
}
#button-1:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(10px);
}
#button-2 {
position: absolute;
width: 100px;
padding: 5px 5px;
border-style: solid;
border-width: 2px;
border-radius: 10px;
border-color: darkslategray;
background-color: antiquewhite;
box-shadow: 0px 9px gray;
cursor: pointer;
top: 62%;
left: 50%;
/* if i remove this line, translation works as expected
but then the button is no longer centered horizontally
consequently, keeping the line breaks the affect
but the button can be centered horizontally
*/
transform: translate(-50%, 0);
}
#button-2:hover {
background-color: cornsilk;
}
#button-2:active {
background-color: cornsilk;
box-shadow: 0px 3px gray;
transform: translate(-50px, 5px);
}
<h2>Animated Button - "Pressed Effect"</h2>
<div class=container>
<button id="button-1">Btn1</button>
<button id="button-2">Btn2</button>
</div>
Note: as others have suggested you may like to look into using flex (or grid) to position your buttons rather than having to mess around with positioning using absolute and translations. The translate for Y could then remain as in the original and you wouldn't be translating in the X direction at all.
you have gotten your X and Y axis mixed up.
you translated via translate(-50%, 0) which moves it by an X of -50% and a Y of nothing, you can fix this by changing it to translate(0, -50%) which will move it down a Y of -50%, and an X of 0.
test the snippet:
.container {
position: relative width: 600px;
height: 600px;
}
#button-1 {
position: absolute;
padding: 15px 25px;
font-size: 24px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #4CAF50;
border: ridge;
border-radius: 15px;
box-shadow: 0 9px #999;
top: 50%;
left: 25%;
}
#button-1:hover {
background-color: #3e8e41
}
#button-1:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(10px);
}
#button-2 {
position: absolute;
width: 100px;
padding: 5px 5px;
border-style: solid;
border-width: 2px;
border-radius: 10px;
border-color: darkslategray;
background-color: antiquewhite;
box-shadow: 0px 9px gray;
cursor: pointer;
top: 62%;
left: 50%;
/* if i remove this line, translation works as expected
but then the button is no longer centered horizontally
consequently, keeping the line breaks the affect
but the button can be centered horizontally
*/
transform: translate(0, -50%);
}
#button-2:hover {
background-color: cornsilk;
}
#button-2:active {
background-color: cornsilk;
box-shadow: 0px 3px gray;
transform: translateY(5px);
}
<h2>Animated Button - "Pressed Effect"</h2>
<div class=container>
<button id="button-1">Btn1</button>
<button id="button-2">Btn2</button>
</div>

Why doesn't the css `rotateY` property work on safari

Below is my html and css code. It is pretty simple. I want to show a square \F1FC on a red react.
.parent::before {
position: absolute;
content: '';
width: 40px;
height: 40px;
background-color: red;
border-radius: 10px 0px 0px 10px;
transform: perspective(5px) rotateY(-2deg);
z-index: -1;
}
p::before {
content: "\F1FC";
color: black;
margin-left: 15px;
}
<div class="parent">
<p></p>
</div>
This code works fine on chrome but doesn't work on safari. Half of the square is hidden by the p::before. Below is a screen shot on safari:
Below is the screenshot for chrome:
This is some kind of weird bug in Safari and pseudo elements. My solution for this issue was to counter the transform: rotateY(-2deg); on the parent pseudo element since it was causing the issue.
Add display: block; and transform: rotateY(1deg); to p::before. The small rotation doesn't seem to affect how the square looks and it fixes it for me in Safari.
.parent::before {
position: absolute;
content: '';
width: 40px;
height: 40px;
background-color: red;
border-radius: 10px 0px 0px 10px;
transform: perspective(5px) rotateY(-2deg);
z-index: -1;
}
p::before {
content: "\F1FC";
color: black;
display: block;
margin-left: 15px;
transform: rotateY(1deg);
}
<div class="parent">
<p></p>
</div>

z-index does not apply on a custom nested tooltip

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/

Top and bottom: different transition

I have an oval, position defined by absolute and "top: -2px". If I add a border to it when hovered, the result is the lower part of the following image, which is still aligned to the center. However if I define the position by "bottom: ??px", the result becomes the upper part, in which the oval is raised up.
Can I achieve the lower part result when I define the position by "bottom"?
CSS for oval:
#oval
{
position: absolute;
top: -2px;
left: 50%;
transform: translate(-50%, -50%);
padding: 5px 15px;
cursor: pointer;
border: none;
border-radius: 20px;
text-align: center;
color: #fff;
font-size: 15;
-webkit-transition-duration: 0.5s;
transition-duration: 0.5s;
}
#oval:hover
{
border: solid //a new color ;
background-color: //a new color ;
color: #000;
}
Its "relative" parent:
.parent
{
position: relative;
width: 600px;
padding: 30px 10px 10px 10px;
border-style: solid;
border-radius: 20px;
margin: auto;
text-align: center;
font-family: "Arial";
font-size: 14;
}
HTML
<div class="parent">
<input type="button" id="oval" value="<?php echo $value; ?>"
onclick='window.open("<?php echo $link; ?>")'>
....
JSF demo
When changing border colours on hover, it's often a good idea to start off with a transparent border and modify that on hover, rather than adding and removing a border each time. This will save you a lot of headaches such as jumping positions, changing box etc.
#oval
{
position: absolute;
top: -2px;
left: 50%;
transform: translate(-50%, -50%);
padding: 5px 15px;
cursor: pointer;
/* OVER HERE */
border: 2px solid transparent;
border-radius: 20px;
text-align: center;
color: #fff;
font-size: 15;
-webkit-transition-duration: 0.5s;
transition-duration: 0.5s;
}
#oval:hover
{
border-color: black;
background-color: red;
color: black ;
}
Found the solution already.
transform: translate(50%, 50%); right:50% when defining by bottom
transform: translate(-50%, -50%); left:50% when defining by top

Build a Responsive CSS Ribbon

I'm building a component that will be used by others. I need to build a ribbon that needs to be responsive and adapt to the content of the ribbon.
I know how to do it using fixed sized borders, as shown in this example.
But if I change the text inside the ribbon, I get something like
this.
Which css technique can I use to make this component?
IMPORTANT: I can't use JS. Only CSS3 and HTML.
Here is a pure CSS solution, where the width of the ribbon will adapt to the width of the content:
.ribbon {
float:left;
clear: left;
display: inline-block;
position: relative;
height: 40px;
margin:12px 0;
padding: 0 4px;
color: rgb(255,255,255);
font-size: 10px;
font-family: verdana, sans-serif;
font-weight: bold;
background-color: rgb(255,0,0);
box-shadow: -2px 2px 2px rgb(0,0,0);
}
.ribbon::before {
content: '';
display: inline-block;
position: absolute;
top: 12px;
left: -24px;
z-index: -12;
width: 12px;
height: 16px;
border: 12px solid rgb(255,255,255);
border-top-color: rgba(0,0,0,0);
border-right-color: rgb(215,0,0);
}
.ribbon::after {
content: '';
display: inline-block;
position: absolute;
top: 6px;
right: -14px;
z-index: 12;
width: 28px;
height: 28px;
background-color: rgb(255,255,255);
transform: rotate(45deg);
box-shadow: inset 2px -1px 1px -1px rgb(0,0,0);
}
.ribbon span {
display: inline-block;
position: relative;
left: 6px;
width: 66%;
margin-top: 4px;
line-height: 16px;
}
<div class="ribbon">
<span>Ribbon Example</span>
</div>
<div class="ribbon">
<span>Ribbon Example with lots more text</span>
</div>
<div class="ribbon">
<span>Ribbon Example with a very large amount of text to show what happens when the ribbon contains an entire sentence</span>
</div>
Play around with line-height on the text (or add it). Increase the line-height px amount.
It'd be nice to see a jsfiddle of this in action where I can help you.