.btn-text {
background: transparent;
box-sizing: border-box;
text-decoration: none;
box-shadow: inset 0 0 0 1px transparent;
border-bottom: 1px solid transparent;
color: red;
padding: 8px 12px 0;
font-size: inherit;
font-weight: 500;
position: relative;
width:100px;
display:block;
vertical-align: middle;
animation: before 0.4s ease;
transition: all 0.4s ease;
margin-top: 30px;
}
.btn-text::before, .btn-text::after {
box-sizing: inherit;
content: "";
position: absolute;
width: 100%;
height: 100%;
}
.btn-text:active {
transform: translateY(0);
box-shadow: 0 1rem 0.5rem rgba(0, 0, 0, 0.2);
}
.btn-text:hover {
text-decoration: none;
color: red;
border-bottom: 1px solid transparent;
}
.btn-text::before, .btn-text::after {
top: 0;
left: 0;
height: 100%;
width: 100%;
transform-origin: center;
}
.btn-text::before {
border-top: 1px solid red;
border-bottom: 1px solid red;
transform: scale3d(0, 1, 1);
}
.btn-text::after {
border-left: 1px solid red;
border-right: 1px solid red;
transform: scale3d(1, 0, 1);
}
.btn-text:hover::before, .btn-text:hover::after {
animation: border 0.5s ease forwards;
}
.btn-text span {
display: block;
border-bottom: 1px solid red;
margin-top: 8px;
}
#keyframes border {
to{
transform: scale3d(1,1,1);
}
}
<a href="#!" class="btn-text " style="width: fit-content">know
more
<span></span>
</a>
I am trying to add a cool hover in animation effect. When I hover over the button I am calling an animation which scaling up borders .
My problem is that when I hover out of button it goes back to the initial state without animation.
I want that the same animation should reverse when I hover out.
You don't need an animation for this, you need a transition...like so:
Codepen Demo
* {
box-sizing: border-box;
}
.btn-text {
background: transparent;
text-decoration: none;
box-shadow: inset 0 0 0 1px transparent;
border-bottom: 1px solid transparent;
color: red;
padding: 8px 12px 0;
font-size: inherit;
font-weight: 500;
position: relative;
width: 100px;
display: block;
vertical-align: middle;
margin-top: 30px;
margin-left: 30px;
}
.btn-text::before,
.btn-text::after {
box-sizing: inherit;
content: "";
position: absolute;
width: 100%;
height: 100%;
transition: transform .5s;
}
.btn-text:hover {
text-decoration: none;
color: red;
border-bottom: 1px solid transparent;
}
.btn-text::before,
.btn-text::after {
top: 0;
left: 0;
height: 100%;
width: 100%;
transform-origin: center;
}
.btn-text::before {
border-top: 1px solid red;
border-bottom: 1px solid red;
transform: scale3d(0, 1, 1);
}
.btn-text::after {
border-left: 1px solid red;
border-right: 1px solid red;
transform: scale3d(1, 0, 1);
}
.btn-text:hover::before {
transform: scale3d(1, 1, 1);
}
.btn-text:hover::after {
transform: scale3d(1, 1, 1);
}
.btn-text span {
display: block;
border-bottom: 1px solid red;
margin-top: 8px;
}
<a href="#!" class="btn-text " style="width: fit-content">know more
<span></span>
</a>
Related
I need to turn around the hover effect of an element. Right now, the border disappears when you hover over it, but I want it to be hidden by default and only appears when you hover over it?
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #fcf3ec;
}
.button {
--offset: 10px;
--border-size: 2px;
display: block;
position: relative;
padding: 1.5em 3em;
appearance: none;
border: 0;
background: transparent;
color: #e55743;
text-transform: uppercase;
letter-spacing: .25em;
outline: none;
cursor: pointer;
font-weight: bold;
border-radius: 0;
box-shadow: inset 0 0 0 var(--border-size) currentcolor;
transition: background .8s ease;
}
.button:hover {
background: rgba(100, 0, 0, .03);
}
.button__horizontal,
.button__vertical {
position: absolute;
top: var(--horizontal-offset, 0);
right: var(--vertical-offset, 0);
bottom: var(--horizontal-offset, 0);
left: var(--vertical-offset, 0);
transition: transform .8s ease;
will-change: transform;
}
.button__horizontal::before .button__vertical::before {
content: '';
position: absolute;
border: inherit;
}
.button__horizontal {
--vertical-offset: calc(var(--offset) * -1);
border-top: var(--border-size) solid currentcolor;
border-bottom: var(--border-size) solid currentcolor;
}
.button__horizontal::before {
top: calc(var(--vertical-offset) - var(--border-size));
bottom: calc(var(--vertical-offset) - var(--border-size));
left: calc(var(--vertical-offset) * -1);
right: calc(var(--vertical-offset) * -1);
}
.button:hover .button__horizontal {
transform: scaleX(0);
}
.button__vertical {
--horizontal-offset: calc(var(--offset) * -1);
border-left: var(--border-size) solid currentcolor;
border-right: var(--border-size) solid currentcolor;
}
.button__vertical::before {
top: calc(var(--horizontal-offset) * -1);
bottom: calc(var(--horizontal-offset) * -1);
left: calc(var(--horizontal-offset) - var(--border-size));
right: calc(var(--horizontal-offset) - var(--border-size));
}
.button:hover .button__vertical {
transform: scaleY(0);
}
<button class="button">
Fancy Button
<div class="button__horizontal"></div>
<div class="button__vertical"></div>
</button>
Here you can see how the effect works and also the original code:
https://codepen.io/electerious/details/qPjbGm
How can I make this effect the other way round?
All you need to do is change where you use the transform.
.button__vertical {
transform: scaleY(0);
--horizontal-offset: calc(var(--offset) * -1);
border-left: var(--border-size) solid currentcolor;
border-right: var(--border-size) solid currentcolor;
}
.button:hover .button__vertical {
transform: scaleY(1);
}
With that its not visible and once you hover you scale it. you will obvs need to do the same for the button__horizontal class but for the scaleX
Here is an easier idea with less of code and only the button tag:
.button {
--offset: 10px;
--border-size: 2px;
padding: 1.5em 3em;
border: var(--offset) solid transparent;
appearance: none;
color: #e55743;
text-transform: uppercase;
letter-spacing: .25em;
cursor: pointer;
font-weight: bold;
--_g: currentColor var(--border-size),#0000 0 calc(100% - var(--border-size)),currentColor 0;
background:
linear-gradient(90deg,var(--_g)) 50%/calc(100% - 2*var(--offset)) 100% border-box,
linear-gradient( var(--_g)) 50%/100% calc(100% - 2*var(--offset)) border-box,
padding-box;
background-repeat: no-repeat;
clip-path: inset(var(--offset));
transition: .8s ease;
}
.button:hover {
background-color: rgba(100, 0, 0, .03);
clip-path: inset(0);
}
body {
display: grid;
place-content: center;
height: 100vh;
margin: 0;
background: #fcf3ec;
}
<button class="button">Fancy Button</button>
I am designing a FM player using pure CSS (no javascript) and tested the layout in Chrome, Firefox, Internet Explorer (IE), and Edge browsers. Except Internet Explorer, the layout shows 99% accuracy as below.
The layout in IE is shown below,
Is it possible to get 100% layout accuracy in all cross-browsers (others like Opera, Safari, etc.)?
The HTML code is used is below,
<body>
<div id="player">
<audio id="musicPlayer" autoplay="autoplay">
<source src="hls.mp3"/>
</audio>
<span id="playPause" onclick="playPause()"><img src="images/play.png" id="playMusic"/></span>
<span id="time">00:00:00</span>
<span id="volumeIcon"><img src="images/volume.png" id="volume"/></span>
<input type="range" id="changeVolume" oninput="SetVolume(this.value)" onchange="SetVolume(this.value)" step="1" min="0" max="100" value="100"/>
</div>
</body>
and CSS code is below,
body {
width:100%;
margin:0 auto;
padding:0px;
font-family:helvetica;
}
#player {
width:400px;
margin:0 auto;
padding:5px;
box-sizing:border-box;
border-radius: 4px;
border: 1px outset darkgreen;
box-shadow: 5px 0 5px -5px black, -5px 0 5px -5px black;
background-image: linear-gradient(lightgreen, PaleGreen, lightgreen);
}
#time {
float:left;
height:20px;
line-height:20px;
margin-left:2px;
margin-right:5px;
margin-top:3px;
}
#playMusic, #pauseMusic {
float:left;
height:18px;
margin-left:2px;
margin-right:5px;
margin-top:3px;
cursor: default;
border-radius: 3px;
border: 1px solid limegreen;
background-image: linear-gradient(lightgreen, PaleGreen, lightgreen);
outline:none;
}
#playMusic:hover, #pauseMusic:hover {
background:#94d362;
border-radius: 3px;
border: 1px solid ForestGreen;
background-color:lightgreen;
background: hsl(100, 100%, 85%);
}
input[type=range] {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
width: 120px;
height:18px;
line-height:18px;
margin-left:2px;
margin-right:5px;
margin-top:3px;
position: absolute;
background-color: transparent;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 3px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0;
background: #228442;
border-radius: 3px;
border: 0;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 0;
border: 0;
height: 10px;
width: 10px;
border-radius: 10px;
background: darkgreen;
cursor: pointer;
-webkit-appearance: none;
margin-top: -4px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #228442;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 3px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0;
background: #228442;
border-radius: 3px;
border: 0;
}
input[type=range]::-moz-range-thumb {
box-shadow: 0;
border: 0;
height: 10px;
width: 10px;
border-radius: 10px;
background: darkgreen;
cursor: pointer;
-webkit-appearance: none;
margin-top: -4px;
}
input[type=range]::-ms-track {
width: 100%;
height: 3px;
cursor: pointer;
animate: 0.2s;
background: transparent;
border-color: transparent;
border-width: 3px 0;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #228442;
border: 0;
border-radius: 3px;
box-shadow: 0;
}
input[type=range]::-ms-fill-upper {
background: #228442;
border: 0;
border-radius: 3px;
box-shadow: 0;
}
input[type=range]::-ms-thumb {
box-shadow: 0;
border: 0;
height: 10px;
width: 10px;
border-radius: 10px;
background: darkgreen;
cursor: pointer;
margin: 0;
}
input[type=range]:focus::-ms-fill-lower {
background: #228442;
}
input[type=range]:focus::-ms-fill-upper {
background: #228442;
}
#volume {
margin-left:134px;
width:20px;
}
The live test URL: https://biox.ml/fm
After some research, I finally found out that you should use the flex positioning (supported by IE11).
First, I edited the HTML design to use block elements (and to pack together the volume icon and range input to simplify the CSS styling).
I set a display:flex for div#player to enable flex positioning.
I put a flex-grow:1 to div#time to let it fill the remaining space.
I put to div#volume an align-items:center style to vertical align the range input and an align-content:flex-end to place the volume box to the right of the div#player.
Finally, I set the top and the bottom paddings of the range input to 0 for IE11, and the height to 100% otherwise IE crops the thumb.
Plus, some minor changes for the finishing and code cleaning.
body {
width: 100%;
margin: 0 auto;
padding: 0px;
font-family: helvetica;
}
/* Beginning of the edited part */
#player {
display: flex;
height: 28px;
width: 400px;
align-items: center;
margin: 0 auto;
padding: 0 5px 0 5px;
background-image: linear-gradient(lightgreen, PaleGreen, lightgreen);
border-radius: 4px;
border: 1px outset darkgreen;
box-sizing: border-box;
box-shadow: 5px 0 5px -5px black, -5px 0 5px -5px black;
}
div#playPause,
div#volume {
height: 18px;
}
div#playPause {
margin-right: 5px;
border: 1px solid limegreen;
border-radius: 3px;
outline: none;
}
div#volume {
display: flex;
align-items: center;
align-content: flex-end;
}
div#playPause img,
div#volume img {
height: 100%;
}
div#time {
flex-grow: 1;
}
div#volume input[type=range] {
width: 120px;
height:100%;
margin: 0;
padding: 0 0 0 5px;
/* 0 paddings is important here */
background-color: transparent;
}
div#volume input[type=range]:focus {
outline: none;
}
/* End of the edited part
Below untouched specific-browser styling the "skin" of the range input
"Untouched" except the prefix "div#volume"
*/
div#volume input[type=range] {
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
}
div#volume input[type=range]:focus {
outline: none;
}
div#volume input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 3px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0;
background: #228442;
border-radius: 3px;
border: 0;
}
div#volume input[type=range]::-webkit-slider-thumb {
box-shadow: 0;
border: 0;
height: 10px;
width: 10px;
border-radius: 10px;
background: darkgreen;
cursor: pointer;
-webkit-appearance: none;
margin-top: -4px;
}
div#volume input[type=range]:focus::-webkit-slider-runnable-track {
background: #228442;
}
div#volume input[type=range]::-moz-range-track {
width: 100%;
height: 3px;
cursor: pointer;
animate: 0.2s;
box-shadow: 0;
background: #228442;
border-radius: 3px;
border: 0;
}
div#volume input[type=range]::-moz-range-thumb {
box-shadow: 0;
border: 0;
height: 10px;
width: 10px;
border-radius: 10px;
background: darkgreen;
cursor: pointer;
-webkit-appearance: none;
margin-top: -4px;
}
div#volume input[type=range]::-ms-track {
width: 100%;
height: 3px;
cursor: pointer;
animate: 0.2s;
background: transparent;
border-color: transparent;
border-width: 3px 0;
color: transparent;
}
div#volume input[type=range]::-ms-fill-lower {
background: #228442;
border: 0;
border-radius: 3px;
box-shadow: 0;
}
div#volume input[type=range]::-ms-fill-upper {
background: #228442;
border: 0;
border-radius: 3px;
box-shadow: 0;
}
div#volume input[type=range]::-ms-thumb {
box-shadow: 0;
border: 0;
height: 10px;
width: 10px;
border-radius: 10px;
background: darkgreen;
cursor: pointer;
margin: 0;
}
div#volume input[type=range]:focus::-ms-fill-lower {
background: #228442;
}
div#volume input[type=range]:focus::-ms-fill-upper {
background: #228442;
}
<div id="player">
<audio id="musicPlayer" autoplay="autoplay">
<source src="hls.mp3"/>
</audio>
<div id="playPause" onclick="playPause()">
<img src="https://biox.ml/fm/images/play.png" id="playMusic" />
</div>
<div id="time">00:00:00</div>
<div id="volume">
<img src="https://biox.ml/fm/images/volume.png" id="playMusic" />
<input type="range" id="changeVolume" oninput="SetVolume(this.value)" onchange="SetVolume(this.value)" step="1" min="0" max="100" value="100" />
</div>
</div>
I think that changing the vertical align property in the CSS might help:
#changeVolume{
vertical-align: middle;
}
Update
You could try doing this:
#player{
display: table-cell;
vertical-align: middle;
}
#changeVolume{
display: inline-block;
}
I hope so that would work...
I have made this button by editing "Simple Hover Effect by Vincent Durand". But the problem is that some css in my blog is overlapping. So it is not aligning to middle correctly. I cant find which one it may be. I tried using !important tag in some places. But I guess it didn't work out. What I need to know where should I use !important in this code to align the button to middle? Or will I need a new css element to do that?
<!-- Awesome button css Start -->
.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
text-align: center;
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
<!-- Awesome button css End -->
<div class="btn-margin">
<a class="btn btn-green" href="#">
Click Here To See Answers
</a>
</div>
Add *{box-sizing:border-box;} to ur css
<!-- Awesome button css Start -->
*{box-sizing:border-box;}
.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
text-align: center;
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
<!-- Awesome button css End -->
<div class="btn-margin">
<a class="btn btn-green" href="#">
Click Here To See Answers
</a>
</div>
Use this CSS to center align the button
.btn-green {
background-color: #1AAB8A;
position: relative;
left: 50%;
transform: translateX(-50%);
}
<!-- Awesome button css Start -->.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
position: relative;
left: 50%;
transform: translateX(-50%);
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
position: relative;
left: 50%;
transform: translateX(-50%);
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,
.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,
.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,
.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
<!-- Awesome button css End -->.btn-green {}
<div class="btn-margin">
<a class="btn btn-green" href="https://myneobuxportal.blogspot.com/p/answer-gamer-quiz-v2.html">
Click Here To See Answers
</a>
</div>
add one parent div and set this div text-align: center;
<!-- Awesome button css Start -->
.demo{
text-align: center;
}
.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
text-align: center;
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
<!-- Awesome button css End -->
<div class="Demo">
<div class="btn-margin">
<a class="btn btn-green" href="#">
Click Here To See Answers
</a>
</div>
</div>
In the end the problem was with the comment :(
I used html comment in css. That's why this happened. Thanks #CharuMaheshwari for mentioning that out. Also another thanks for other 3 answers. All of them worked.
With #CharuMaheshwari help this is the code I decided to use.
/* Awesome button css Start */
.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
text-align: center;
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
/* Awesome button css End */
<div class="btn-margin">
<a class="btn btn-green" href="#">
Click Here To See Answers
</a>
</div>
Hi I'm trying to make a Pomodoro clock. I've made a play button by removing border-right and increasing border-left width to create a triangle.
My questions is - how do I apply border-radius to it?
https://codepen.io/jenlky/pen/ypQjPa?editors=1100
<div id="all-buttons" class="buttons">
<!-- play button -->
<div id="play" class="play-button"></div>
<!-- pause button -->
<div id="pause">
<div class="line-1"></div>
<div class="line-2"></div>
</div>
<!-- end of play and pause button-->
</div>
.play-button {
z-index: 2;
width: 48px;
height: 48px;
border-style: solid;
border-width: 24px 0px 24px 48px;
border-color: white white white #FF8F83;
}
HTML play button:
.circle_inner{
position: relative;
height: 100%;
}
.circle_inner:before{
content: "";
display: block;
width: 0;
height: 0;
border-style: solid;
border-width: 10px 0 10px 20px;
border-color: transparent transparent transparent #000;
position: absolute;
top: 50px;
left: 50%;
margin: -10px 0 0 -7px;
}
<div class="circle_inner">
</div>
Try this (Less)
<div class="control play">
<span class="left"></span><span class="right"></span>
</div>
.control {
#color: #ffb160;
#highlight: darken(#color, 10%);
#duration: 0.4s;
#sin: 0.866;
#size: 112px;
border-radius: 50%;
margin: 20px;
padding: #size*0.25;
width: #size;
height: #size;
font-size: 0;
white-space: nowrap;
text-align: center;
cursor: pointer;
&, .left, .right, &:before {
display: inline-block;
vertical-align: middle;
transition: border #duration, width #duration, height #duration, margin #duration;
transition-tiomig-function: cubic-bezier(1, 0, 0, 1);
}
&:before {
content: "";
height: #size;
}
&.pause {
.left, .right {
margin: 0;
border-left: #size*0.33 solid #color;
border-top: 0 solid transparent;
border-bottom: 0 solid transparent;
height: #size*#sin;
}
.left {
border-right: #size*0.2 solid transparent;
}
}
&.play {
#border: #size/4;
.left {
margin-left: #size/6;
border-left: #size*#sin/2 solid #color;
border-top: #border solid transparent;
border-bottom: #border solid transparent;
border-right: 0px solid transparent;
height: #size - 2*#border;
}
.right {
margin: 0;
border-left: #size*#sin/2 solid #color;
border-top: #border solid transparent;
border-bottom: #border solid transparent;
height: 0px;
}
}
&:hover {
border-color: #highlight;
.left, .right {
border-left-color: #highlight;
}
}
}
I have crafted a small css drop down button/menu which I am now trying to animate.
I had the menu initially going from display: none to display:block when hovering the parent, but I cannot animate this - so I have tried swapping to opacity: 0, height: 0 to opacity: 1, height: auto but this is causing some weird functionality with the menu. Let me show you what I mean. Here is the original menu code :
HTML :
<div className="account-dropdown">
<button className="dropbtn">
<FormattedMessage
id="header.account"
defaultMessage={`Account`} />
</button>
<div className="dropdown-content">
<a>Order History</a>
<a>Settings</a>
<a onClick={logOut}>Logout</a>
</div>
</div>
The scss :
.account-dropdown {
position: relative;
display: inline-block;
&:hover {
.dropdown-content {
display: block;
}
.dropbtn {
color: red;
}
}
.dropbtn {
border: none;
cursor: pointer;
margin: 2rem 1rem;
transition: all 0.3s;
color: black;
background-color: #fff;
}
.dropdown-content {
display: none;
padding: 3rem 3rem 1rem 3rem;
position: absolute;
top: 5rem;
left: -17.6rem;
background-color: #fff;
min-width: 250px;
width: 100%;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
border: solid 1px #e8e8e8;
z-index: 1;
color: rgba(0, 0, 0, 0);
transition: all 0.3s;
&:after, &:before {
bottom: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
&:after {
border-color: rgba(255, 255, 255, 0);
border-bottom-color: #ffffff;
border-width: 7px;
left: 75%;
margin-left: 26px;
}
&:before {
border-color: rgba(113, 158, 206, 0);
border-bottom-color: #e8e8e8;
border-width: 8px;
left: 75%;
margin-left: 25px;
}
a {
text-align: left;
color: black;
padding-bottom: .8rem;
text-decoration: none;
display: block;
cursor: pointer;
transition: all 0.3s;
&:hover {
color: black;
}
&:last-child {
margin-top: .4rem;
padding-top: .8rem;
border-top: solid 1px #e8e8e8;
}
}
}
}
Here it is running in a fiddle (without the rems or scss vars) https://jsfiddle.net/tqf1r0mm/7/
And here is a fiddle when I swap the display none for opacity and height -> https://jsfiddle.net/tqf1r0mm/10/ .
You can see both that the animation is janky and also if you hover below account button the menu opens (I would only like it to open when the user hovers account).
Any ideas on how to fix this to get a nice smooth animation? Any advice would be great. Thanks!
you may be using the atribute transition: all and is because that the animation looks like that
but instead of using height:0; you can use: visibility:hidden; and visibility:visible on hover to avoid that animation problem
something like this
.test {
padding-left: 300px;
.account-dropdown {
position: relative;
display: inline-block;
&:hover {
.dropdown-content {
opacity: 1;
visibility:visible;
}
.dropbtn {
color: black;
}
}
.dropbtn {
border: none;
cursor: pointer;
margin: 20px 10px;
transition: all 0.3s;
color: black;
background-color: #fff;
}
.dropdown-content {
opacity: 0;
visibility:hidden;
padding: 3rem 3rem 1rem 3rem;
position: absolute;
top: 50px;
left: -176px;
background-color: #fff;
min-width: 250px;
width: 100%;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
border: solid 1px #e8e8e8;
z-index: 1;
color: rgba(0, 0, 0, 0);
transition: all 0.3s;
&:after,
&:before {
bottom: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
&:after {
border-color: rgba(255, 255, 255, 0);
border-bottom-color: #ffffff;
border-width: 7px;
left: 75%;
margin-left: 26px;
}
&:before {
border-color: rgba(113, 158, 206, 0);
border-bottom-color: #e8e8e8;
border-width: 8px;
left: 75%;
margin-left: 25px;
}
a {
text-align: left;
color: black;
padding-bottom: 8px;
text-decoration: none;
display: block;
cursor: pointer;
transition: all 0.3s;
&:hover {
color: black;
}
&:last-child {
margin-top: 4px;
padding-top: 8px;
border-top: solid 1px #e8e8e8;
}
}
}
}
}
Use visibility instead of height, but use the opacity as well, because you can't animate visibility either. Also put the trigger on .dropbtn instead of .account-dropdown to avoid it activating the hover state when you hover anywhere except the button.
I don't know SCSS so I used CodePen to convert to regular CSS. Here's the code I used:
.test {
padding-left: 300px;
}
.test .account-dropdown {
position: relative;
display: inline-block;
}
.test .account-dropdown .dropbtn:hover~.dropdown-content {
visibility: visible;
opacity: 1;
}
.test .account-dropdown .dropdown-content:hover {
visibility: visible;
opacity: 1;
}
.test .account-dropdown:hover .dropbtn {
color: black;
}
.test .account-dropdown .dropbtn {
border: none;
cursor: pointer;
margin: 20px 10px;
transition: all 0.3s;
color: black;
background-color: #fff;
}
.test .account-dropdown .dropdown-content {
opacity: 0;
visibility: hidden;
padding: 3rem 3rem 1rem 3rem;
position: absolute;
top: 50px;
left: -176px;
background-color: #fff;
min-width: 250px;
width: 100%;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
border: solid 1px #e8e8e8;
z-index: 1;
color: transparent;
transition: all 0.3s;
}
.test .account-dropdown .dropdown-content:after,
.test .account-dropdown .dropdown-content:before {
bottom: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.test .account-dropdown .dropdown-content:after {
border-color: rgba(255, 255, 255, 0);
border-bottom-color: #ffffff;
border-width: 7px;
left: 75%;
margin-left: 26px;
}
.test .account-dropdown .dropdown-content:before {
border-color: rgba(113, 158, 206, 0);
border-bottom-color: #e8e8e8;
border-width: 8px;
left: 75%;
margin-left: 25px;
}
.test .account-dropdown .dropdown-content a {
text-align: left;
color: black;
padding-bottom: 8px;
text-decoration: none;
display: block;
cursor: pointer;
transition: all 0.3s;
}
.test .account-dropdown .dropdown-content a:hover {
color: black;
}
.test .account-dropdown .dropdown-content a:last-child {
margin-top: 4px;
padding-top: 8px;
border-top: solid 1px #e8e8e8;
}
<div class="test">
<div class="account-dropdown">
<button class="dropbtn">
Account
</button>
<div class="dropdown-content">
<a>Order History</a>
<a>Settings</a>
<a>Logout</a>
</div>
</div>
</div>
I also added another hover class when you hover over .dropdown-content otherwise it dissappears when you try to click on one of the links.