I wanted my button to change the background color on hover with a transition from left to right. This is what I tried:
.btn {
background-color: transparent;
transition-property: background-color, left, right;
transition-duration: 1s;
color: #007eb6;
border: 1px solid #007eb6;
&:hover {
background-color: #007eb6;
color: #fafafa;
border: 1px solid #007eb6;
}
Here is a codepen you can use (Its not mine)
The trick is to set background-position to 0% and on hover change it to 100%
<button>Bangladesh</button>
CSS Code
button {
background-color: red;
color: #fff;
border: none;
outline: none;
padding: 20px 60px;
font-size: 20px;
text-transform: uppercase;
position: relative;
z-index: 1;
cursor: pointer;
}
button::before {
content: "";
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 0;
background-color: green;
transition: .5s;
z-index: -1;
}
button:hover::before {
width: 100%;
}
Related
The screenshot attached explains everything about the desired effect. I was thinking to decrease the border width from 4px to 3px to 2px , I don't want to apply ease-in/ease out effect. As of now, when I hover, it looks like this. I want to change this box through the effect displayed in the first screenshot.
For reference,
I am posting the code below:
&__link {
#include font-text(default, menuitem);
#include token(font-size, sidenav, default);
background-image: none;
text-transform: uppercase;
padding: 1rem;
margin: 0;
&:before {
position: absolute;
right: 1.3rem;
top: 2rem;
width: 1px;
content: '';
background: #fff;
height: 100%;
opacity: 0.3;
}
&:after {
display: inline-block;
vertical-align: middle;
position: relative;
content: '';
width: 10px;
height: 10px;
outline: 1px solid #fff;
top: -1px;
}
&:hover {
#include font-text(default, menuitem);
#include token(font-size, sidenav, hover);
font-weight: 600;
margin: 0;
padding: 1rem;
&:after {
background: white;
box-shadow: 0 0 10px 1px rgba(255, 255, 255, 1);
}
}
}
&:after represents the code for the box. Thanks in advance.
<div class="box">
</div>
.box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 200px;
width: 200px;
text-decoration: none;
background-color: white;
background-image: linear-gradient(#000, #000);
border: 1px solid black;
background-position: 50% 50%;
background-repeat: no-repeat;
background-size: 0% 0%;
transition: .5s;
}
.box:hover {
background-size: 95% 95%;
}
Didnt understand the question too well but this does the attached screenshot animation
Try it - you need to set animations, bcz you want several situations for single event (hover)
Replace these blocks
&:after {
display: inline-block;
vertical-align: middle;
position: relative;
content: '';
width: 0px;
height: 0px;
top: -1px;
background: white;
border: 7px solid #fff;
}
&:hover:after {
animation: sqr .3s linear;
animation-fill-mode: forwards;
}
#keyframes sqr {
30%{
border: 5.5px solid #fff;
width: 3px; height: 3px;
background: black;
}
80%{
border: 4px solid #fff;
width: 6px;
height: 6px;
background: black;
}
100%{
border: 3px solid #fff;
width: 8px;
height: 8px;
transform: scale(1.5);
box-shadow: 0 0 5px 2px #fff;
background: black;
}
}
I'm using a pseudo element in a button to achieve an angled border. But in some browsers and some zoom levels, if you look closely you'll see a faint outline around the pseudo element towards the right of the button on the left edge of the pseudo element.
Here is the fiddle: https://jsfiddle.net/jw1kfmsh/
.button {
position: relative;
padding: 0 20px;
height: 53px;
background-color: red;
border: 4px solid black;
border-right-width: 0;
color: white;
font-weight: 900;
font-size: 14px;
transition: all .425s ease;
text-decoration: none;
display: inline-flex;
align-items: center;
z-index: 1;
filter: blur(0);
}
.button::after {
position: absolute;
content: '';
right: -19px;
top: -4px;
height: 53px;
width: 38px;
background-color: red;
border: 4px solid black;
z-index: -1;
border-left: 0;
transform: skew(-31deg);
transition: all .425s ease;
backface-visibility: hidden;
}
Button Text
I would consider a different idea where you will not have the issue. Make the shape as only one element and rely on overflow to hide the non needed part.
.button {
position: relative;
display:inline-block;
padding: 0 40px 0 20px;
line-height: 53px;
border-left: 4px solid black;
color: white;
font-weight: 900;
font-size: 14px;
text-decoration: none;
overflow:hidden;
z-index: 0;
}
.button::after {
position: absolute;
content: '';
right:0;
top: 0;
left:-5px;
bottom:0;
background: red;
border: 4px solid black;
z-index: -1;
transform: skew(-31deg);
transform-origin:top;
}
Button Text
I am trying to get a CSS tooltip to work correctly which I found on the thoughtbot blog. The only changes that I have made to the code is to change from Scss to CSS, and simplify the html a touch. However, when in CSS, it doesnt work.
The original article can be found here, where there is also a working codepen that I copied as the basis for my CSS version https://robots.thoughtbot.com/you-don-t-need-javascript-for-that
.container {
margin-top: 100px;
margin-left: 100px;
border: 2px solid red;
}
/* //The good stuff */
.tooltip-toggle {
cursor: pointer;
position: relative;
}
/* //Tooltip text container */
.tooltip-toggle::before {
position: absolute;
top: -80px;
left: -80px;
background-color: #2B222A;
border-radius: 5px;
color: #fff;
content: attr(data-tooltip);
padding: 1rem;
text-transform: none;
transition: all 0.5s ease;
width: 160px;
}
/*
//Tooltip arrow */
.tooltip-toggle::after {
position: absolute;
top: -12px;
left: 9px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #2B222A;
content: " ";
font-size: 0;
line-height: 0;
margin-left: -5px;
width: 0;
}
.tooltip-toggle::before {
color: #efefef;
font-family: monospace;
font-size: 16px;
opacity: 0;
pointer-events: none;
text-align: center;
}
.tooltip-toggle::after {
color: #efefef;
font-family: monospace;
font-size: 16px;
opacity: 0;
pointer-events: none;
text-align: center;
}
/* //Triggering the transition */
.tooltip-toogle:hover::before {
opacity: 1;
transition: all 0.75s ease;
}
.tooltip-toggle:hover::after {
opacity: 1;
transition: all 0.75s ease;
}
Below is my html.
<html>
<body>
<div class="container tooltip-toggle" data-tooltip="Sample text for your tooltip!>
<div class="label">Hello
</div>
</div>
</body>
</html>
So, I laughed very hard when I figured your problem out:
/* //Triggering the transition */
.tooltip-toogle:hover::before {
opacity: 1;
transition: all 0.75s ease;
}
.tooltip-toogle:hover
Obviously should be toggle, lol.
Edit: cleaned css and fixed it
.container {
margin-top: 100px;
margin-left: 100px;
border: 2px solid red;
}
/* The good stuff */
.tooltip-toggle {
cursor: pointer;
position: relative;
}
/* Tooltip text container */
.tooltip-toggle::before {
position: absolute;
top: -80px;
left: -80px;
background-color: #2B222A;
border-radius: 5px;
color: #fff;
content: attr(data-tooltip);
padding: 1rem;
text-transform: none;
transition: all 0.5s ease;
width: 160px;
}
/* Tooltip arrow */
.tooltip-toggle::after {
position: absolute;
top: -12px;
left: 9px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #2B222A;
content: " ";
font-size: 0;
line-height: 0;
margin-left: -5px;
width: 0;
}
.tooltip-toggle::before, .tooltip-toggle::after {
color: #efefef;
font-family: monospace;
font-size: 16px;
opacity: 0;
pointer-events: none;
text-align: center;
}
/* Triggering the transition */
.tooltip-toogle:hover::before, .tooltip-toggle:hover::after {
opacity: 1;
transition: all 0.75s ease;
}
I add a ":after" element to all links (simulate a "border-bottom") so on ":hover" i can animate this pseudo element ("height: 100%"). This works fine, but when the link is split with a line-break the pseudo element is broken after the line break.
a {
color: red;
position: relative;
text-decoration: none;
&:after {
transition: height .1s;
background-color: red;
bottom: -3px;
content: '';
display: inline;
height: 3px;
left: 0;
right: 0;
position: absolute;
width: 100%;
z-index: -1;
}
&:hover:after {
height: calc(100% + 4px);
}
&:hover {
color: white;
}
}
Here is a pen:
http://codepen.io/herrfischer/pen/YWKmQJ
Any idea what I am doing wrong?
For an inline element, background will be more efficient: http://codepen.io/gc-nomade/pen/pbzMYP
a {
color: red;
position: relative;
text-decoration: none;
background:linear-gradient(red,red) bottom repeat-x;
background-size:3px 3px;
transition:1s;
&:hover {
background-size:100% 100%;
color: white;
}
}
Stolen from another site - it works with animated background gradient :)
a {
background-image: linear-gradient(red 0%, red 100%);
background-position: bottom;
background-repeat: repeat-x;
background-size: 0 0;
border-bottom: 3px solid red;
color: red;
position: relative;
text-decoration: none;
transition: 150ms ease;
&:hover {
color: white;
background-size: 1em 1.5em;
}
}
Updated the pen.
I have a DIV with an "arrow" at the bottom, not unlike a speech bubble from a comic book, which appears on the hover state:
The arrow is created with the :after and :before pseudo elements.
I have a transition for the hover for the border color and the box shadow.
My problem is that the "arrow" just "appears". No fade like the other items, but I can't figure out how to target the "arrow". "All" does not look right either.
Ideally, I'd love to have a delay on the arrow and a simple fade or wipe.
Here's the CSS:
.item-selector-button {
position: relative;
text-align: center;
cursor: pointer;
border: 1px solid #cecece;
padding: 15px;
border-radius: 0;
color: #000;
width: 160px;
height: 120px;
transition: all ease-in-out 0.1s, box-shadow ease-in-out 0.1s;
}
.item-selector-button .title {
color: #3e53a4;
font-size: 12px;
margin: 0;
padding-top: -3px;
font-family: "PrecisionSans_W_Md", "Helvetica Neue", Arial, sans-serif;
}
.item-selector-button .divider {
height: 1px;
width: 20px;
background-color: #cecece;
margin: 4px auto 10px;
}
.item-selector-button .image {
background: #fff url("../images/box.png") center center no-repeat;
width: 64px;
height: 57px;
margin: 4px auto;
}
.item-selector-button:hover, .item-selector-button.hover {
padding: 14px;
}
.item-selector-button:hover:after, .item-selector-button.hover:after {
content: "";
position: absolute;
bottom: -12px;
left: 68px;
border-width: 12px 12px 0;
border-style: solid;
border-color: #fff transparent;
transition-delay: 0.3s;
}
.item-selector-button:hover:before, .item-selector-button.hover:before {
content: "";
position: absolute;
bottom: -15px;
left: 65px;
border-width: 15px 15px 0;
border-style: solid;
border-color: #3e53a4 transparent;
transition-delay: 0.3s;
}
.item-selector-button:active, .item-selector-button.active {
border-width: 2px;
border-color: #3e53a4;
background-color: #3e53a4;
}
.item-selector-button:active:before, .item-selector-button.active:before {
content: "";
position: absolute;
bottom: -15px;
left: 65px;
border-width: 15px 15px 0;
border-style: solid;
border-color: #3e53a4 transparent;
transition-delay: 0.3s;
}
.item-selector-button:active .title, .item-selector-button.active .title {
color: #fff;
}
.item-selector-button:active .divider, .item-selector-button.active .divider {
background-color: #fff;
}
.item-selector-button:active .image, .item-selector-button.active .image {
background-color: #3e53a4;
}
.item-selector-button:active:hover, .item-selector-button.active:hover {
padding: 15px;
box-shadow: none;
}
.item-selector-button:active:hover:after, .item-selector-button.active:hover:after {
content: "";
position: absolute;
bottom: -12px;
left: 68px;
border-width: 12px 12px 0;
border-style: solid;
border-color: #3e53a4 transparent;
transition-delay: 0.3s;
}
.item-selector-button.disabled {
pointer-events: none;
cursor: not-allowed;
}
.item-selector-button.disabled .title {
color: #c3c3c3;
}
.item-selector-button.disabled .image {
background-image: url("../images/box-disabled.png");
}
.item-selector-button.disabled:hover {
padding: 15px;
border: 1px solid #cecece;
box-shadow: none;
}
You only have pseudoelements on the hovered element, so there is nothing to transition from/to. You need to add the pseudo elements on the non-hover state element.
Example transitioning visibility:
.item-selector-button:before {
.arrow-inside(...);
transition:all 5s ease;
transition-delay: 0.3s;
visibility:hidden;
}
.item-selector-button:after {
.arrow-outside(...);
transition:all 5s ease;
transition-delay: 0.3s;
visibility:hidden;
}
.item-selector-button:hover:before {
visibility:visible;
}
.item-selector-button:hover:after {
visibility:visible;
}