Is there a way to prevent a CSS Transition ending prematurely? - css

I have a transition set on an styled button, which is getting triggered on :active state. So it smoothly goes to a pressed state, then smoothly goes back to normal state.
My problem is that the transition animation seems to end prematurely, meaning even if transition-duration is 2s, it will last much shorter, especially on mobile device taps.
Meaning the animation works on touchpad taps (relatively long), or holding the button on mobile devices, but I want it to activate and last the full time, on both mouse clicks and mobile taps.
I saw somewhere on the net, that putting the :active state on the parent, then translating the child from the parent will fix the issue, but no success yet.
Here a web environment with my code -> https://stackblitz.com/edit/vitejs-vite-tx57pk?file=src/Button.jsx
And here's the code block itself ⬇️
import styled, { css } from 'styled-components';
export const Button = styled.button`
--easing: cubic-bezier(0.18, 0.89, 0.32, 1.28);
--bg-color: #ddd;
--shadow-color: grey;
width: 100%;
height: 5rem;
color: black;
outline-offset: 5px;
border: none;
text-transform: uppercase;
display: grid;
place-items: center;
font-family: inherit;
font-weight: 700;
touch-action: manipulation;
transition: all 0.5s var(--easing);
background-color: var(--bg-color);
border-radius: 15px;
font-size: 20px;
line-height: 25px;
letter-spacing: 1.25px;
box-shadow: 0px 8px 0px var(--shadow-color);
&:active {
transform: translateY(8px);
box-shadow: 0px 0px 0px var(--shadow-color);
}
`;

Related

An animation problem in the vicinity of the boundary with an element at hover

I use the transform property for animation when I hover and set animation such as rotation to element.
However, this occasionally causes defects like the image below.
Regarding this problem, I confirm that no matter what site I look at it is not written.
And even Twitter to this problem does not correspond!
How should I respond to this problem?
animation problem in the vicinity of the boundary
For example, suppose you have HTML with such a CSS applied.
a {
border-radius: 4px;
display: inline-block;
height: 50px;
text-decoration: none;
width: 150px;
background: #a0f;
border-radius: 4px;
text-align: center;
transition: all 0.6s ease;
box-shadow: 5px 5px #50a
}
span {
color: #fff;
font-weight: bold;
line-height: 50px;
}
#link:hover {
border-radius: 25px;
width: 50px;
}
<div>
<a id="link">
<span>text</span>
</a>
</div>
When hovering to the right boundary of this button, the button repeats expansion and contraction at short intervals.
A problem similar to this is occurring in the twitter gif uploaded above.
How should I fix this problem?

Center vertically menu icon in Chrome for Mobile

I have a menu icon that's perfectly vertically centered in all browsers but in Chrome for Mobile not. This is the code for the menu icon:
-HTML-
<div class="menuIcon">
<p class="im im-menu"></p>
</div>
-CSS-
.menuIcon{
border: 2px solid #ddd;
border-radius: 4px;
cursor: pointer;
display: flex;
margin-left: auto;
padding: 2px 6px;
color: #424242;
transition: background-color 0.8s ease 0s;
}
.menuIcon:hover{
background-color: #ddd;
}
.im {
display: inline-block;
font: normal normal normal 24px/1 'iconmonstr-iconic-font';
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
I tried with line-height: 24px and other properties but with no result. With padding: 6px 2px 2px is more or less centered in Chrome for Mobile but in desktop browsers is malformed so it's not an option. If someone could also explain me this behaviour I will be very grateful.
Here's the link to my website. Remember that the problem is only in Chrome for Mobile.
I upload a screenshot of the problem.

Border-Radius doesn't work in link button on Chrome

I have styled an oval button and it in an a element with the class .button
It works and looks great on firefox, but I get a rectangular button in Chrome, without a border. The link still works but the border and border-radius seems to be misunderstood.
This is the CSS:
a.orange-circle-button {
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
box-shadow: 0 6px 9px 0 rgba(0,0,0,0.4);
border: .5em solid #00667e;
font-size: 1.2em;
text-transform: none;
text-align: center;
font-family: "lato", sans-serif;
line-height: 3em;
color: #ffffff;
background-color: #283f72;
margin: auto;
display: block;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-khtml-border-radius: 50%;
height: 4em;
width: 12em;
position: relative; }
Here is the HTML:
Current Stock
This is it in the wild: https://www.frontiercomputercorp.com/
I am assuming I've done something wrong with the border-radius that's unique to chrome, but I'm not skilled enough to know if it's being caused by the way I'm calling the class.
To recap: In firefox the button is oval (as I wanted)
In Chrome it is rectangular
HeLP!
Remove the following lines and it will be fixed:
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
I tested it in Chrome and it fixed the problem.
The appearance property is used to display an element using a platform-native styling based on the users' operating system's theme.Therefore it overrides your border-radius code as Chrome natively doesn't set border-radius for the button. By not to adding appearance or setting it to none, you won't have this problem in Chrome too.
Just delete these lines below:
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
<a> is a clickable type of element. A hyper-link. display: block will do what you want here.
"The appearance property is used to display an element using a platform-native styling based on the users' operating system's theme."
(I think they are still ugly, but that's not the point here :) )
Here's the CSS now:
a.oval-box{
box-shadow: 0 6px 9px 0 rgba(0,0,0,0.4);
border: .5em solid #00667e;
font-size: 1.2em;
text-transform: none;
text-align: center;
font-family: "lato", sans-serif;
line-height: 3em;
color: #ffffff;
background-color: #283f72;
margin: auto;
display: block;
border-radius: 50%;
-webkit-border-radius: 50%;
height: 4em;
width: 12em;
position: relative; }
a.oval-box:hover {
color:#ffffff;
background-color: #f00667e;
text-decoration: none;
border-color: #f89520;}
I started this with a button so I got stuck thinking button. But as you have pointed out, it's just a styled block and I don't need the button comand at all.
Thanks.

CSS :hover Selector not working as expected with gifs

I am working on a new button styles and currently facing a challenge: my <button> CSS :hover selector is not behaving as expected.
All attempts to making it work have proven futile.
How can I possibly achieve that effectively?
Below is my code:
.button_depression {
background: url(http://67.media.tumblr.com/tumblr_m9atx55D6F1qd1e6no1_400.gif)
no-repeat;
border: 0;
color: #ffffff;
padding: 5px 35px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
cursor: pointer;
border-radius: 5px;
font-family: Times New Roman;
transition-duration: 0.5s;
}
.button_depression:hover {
background-color: #959595;
}
Simply use background for your hover; not background-color as illustrated in the snippet below:
.button_depression:hover {
background: #959595;
}
Brief summary:
background CSS property is a shorthand to set the values for one or more of: background-clip, background-color, background-image, background-origin, background-position, background-repeat, background-size, and background-attachment.
When working without the shorthand, the background-image property supersedes background-color and as such, setting background-color alone without abnegating it (background-image) will result in its precedence.
In other words, background-image: none; in combination with background-color: #959595; will work. (Refer to snippet below)
.button_depression:hover {
background-color: #959595;
background-image: none;
}
(background-image: unset; works well too, but can't tell if supported by all browsers)
Note that you can be achieved the same, using the background shorthand, simply as above, with background: #959595; (which I prefer: simple, less verbose, same result).
More details here ....
You can't see the button hover changing the background color due to the background image. You can set the button image to None on hover and then change the color. This might be what you want. Alternatively you can just set background to the background color you wanted. Your preference how you want to acomplish this.
.button_depression {
background: url(http://67.media.tumblr.com/tumblr_m9atx55D6F1qd1e6no1_400.gif) no-repeat;
border: 0px;
color: #ffffff;
padding: 5px 35px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
cursor: pointer;
border-radius: 5px;
font-family: Times New Roman;
transition-duration: 0.5s;
}
.button_depression:hover {
background: None;
background-color: #959595;
}

In Chrome, adding border-radius also adds a background colour. Why?

I'm trying to add border-radius to an input submit button, but when I do, Chrome is also adding a grey background colour and a box shadow.
How can I just use border-radius to round the corners, and keep the background colour white, and have no box-shadow?
Here's my HTML:
<input type="submit" id="nm-match" class="nm-button" value="Match" />
And my CSS:
.nm-button {
border-radius: 5px;
}
Here's a demo of the problem: http://jsfiddle.net/CJg43/3/
Use your inspector on chrome and scroll to the element .m-button. (for the quickest way right click directly on the button and say inspect element) If you look on the Elements tab (which should be the first one popped up and look on the right side at the styles section it will show all the css styles being applied to that element whether they were put there by you or by chrome (the cool thing about this styles section is the styles are in order of precedence so you can easily tell which styles overwrite which (that being the higher styles overwrite the lower ones)) or even if they are the default for an element (example display: block; are always on block level elements like divs.) This is a handy tool.
So if you do this in your case you will see that chrome applies different styles to input styles. These are mostly being applied because the input[type="submit"]. If you want to overwrite these styles for the most part just overwriting the same styles in your class on your button should suffice. adding the following should be fine if you only want to overwrite the styles for the background color the "box-shadow" (which it's actually the border that is creating that shadow so just add a new border)
.nm-button {
border-radius: 5px;
background-color: #fff;
border: 1px solid #ccc;
}
Also since it's a button suggest something like the following code so it looks clickable.
.nm-button:hover {
background-color: #ddd;
cursor: pointer;
}
Here are the styles put there by chrome in your case. It's alot but chrome also is very minimalistic in it's approach so that all of this is easily overwritable. (P.S. I hope this helped, feel free to leave a comment if you have any questions.)
input[type="button"], input[type="submit"], input[type="reset"], input[type="file"]::-webkit-file-upload-button, button {
padding: 1px 6px;
}
user agent stylesheetinput[type="button"], input[type="submit"], input[type="reset"], input[type="file"]::-webkit-file-upload-button, button {
align-items: flex-start;
text-align: center;
cursor: default;
color: buttontext;
padding: 2px 6px 3px;
border: 2px outset buttonface;
border-image-source: initial;
border-image-slice: initial;
border-image-width: initial;
border-image-outset: initial;
border-image-repeat: initial;
background-color: buttonface;
box-sizing: border-box;
}
user agent stylesheetinput[type="button"], input[type="submit"], input[type="reset"] {
-webkit-appearance: push-button;
white-space: pre;
}
user agent stylesheetinput, input[type="password"], input[type="search"], isindex {
-webkit-appearance: textfield;
padding: 1px;
background-color: white;
border: 2px inset;
border-image-source: initial;
border-image-slice: initial;
border-image-width: initial;
border-image-outset: initial;
border-image-repeat: initial;
-webkit-rtl-ordering: logical;
-webkit-user-select: text;
cursor: auto;
}
user agent stylesheetinput, textarea, keygen, select, button, isindex {
margin: 0em;
font: -webkit-small-control;
color: initial;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
}
user agent stylesheetinput, textarea, keygen, select, button, isindex, meter, progress {
-webkit-writing-mode: horizontal-tb;
}

Resources