I am missing how I should hide the :before element, and only make it visible when it is "inside" the button div, to create a filling effect on the hover button.
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
}
buttt
Set the :before element height to 0 , then change it on :hover:before to 100%
The snippet
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 0;
z-index: -1;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
height:100%;
}
buttt
you can wrap your link in a div and set overflow to hidden like this :
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.wrap {
float: left;
width: 65px;
height: 32px;
overflow: hidden;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
}
<div class="wrap">buttt</div>
Add display:inline-block and overflow:hidden to a.button styling, as default display of a tag is inline.
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
overflow:hidden;
display:inline-block; /* Add this */
overflow:hidden; /* Add this */
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
}
buttt
Only insert This:
a.button {
display: inline-block;
overflow: hidden;
//Other Codes...
}
a.button {
font-size: 20px;
color: #000;
border: 2px solid #000;
padding: 8px 12px;
position: relative;
margin: 0;
display: inline-block;
overflow: hidden;
}
a.button:before {
transition: 0.5s all ease-in-out;
content: '';
position: absolute;
background-color: red;
top: 100%;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
a.button:hover {
transition: 0.6s all ease-in-out;
color: #fff;
}
a.button:hover:before {
transition: 0.5s all ease-in-out;
top: 0;
}
buttt
Related
I am trying to build an underline under the nav menu on hover. I'm using the 'content' trick because I couldn't make what I wanted with just text decoration.
I want something like this but with a smooth transition.
Here's the CSS for it without transition because I couldn't make it work.
div {
display: flex;
align-items: center;
color: #ab9b8c;
font-size: 20px;
letter-spacing: 1.5px;
text-decoration: none;
height: 100%;
cursor: pointer;
transition: height 2s;
position: relative;
}
div:hover::after {
content: '';
position: absolute;
bottom: -1px;
width: 30px;
height: 3px;
border-radius: 200px;
border: 1px solid #9f9182;
}
<div>test
<div/>
As Paulie_D mentioned, you can't do transitions on position attributes. See: https://www.w3schools.com/cssref/pr_class_position.asp "Animatable: no."
Several other attributes are fair game though. Here's one using the width and the border:
div {
display: flex;
align-items: center;
color: #ab9b8c;
font-size: 20px;
letter-spacing: 1.5px;
text-decoration: none;
height: 100%;
cursor: pointer;
transition: height 2s;
position: relative;
}
div::after {
content: '';
position: absolute;
bottom: -1px;
width: 0px;
height: 3px;
border-radius: 200px;
border: 0px solid #9f9182;
transition: all 0.2s linear;
}
div:hover::after {
width: 30px;
border: 1px solid #9f9182;
transition: all 0.2s linear;
}
<div>test
</div>
Here's an opacity:
div {
display: flex;
align-items: center;
color: #ab9b8c;
font-size: 20px;
letter-spacing: 1.5px;
text-decoration: none;
height: 100%;
cursor: pointer;
transition: height 2s;
position: relative;
}
div::after {
content: '';
position: absolute;
bottom: -1px;
width: 30px;
height: 3px;
border-radius: 200px;
border: 1px solid #9f9182;
opacity: 0;
transition: all 0.2s linear;
}
div:hover::after {
opacity: 1;
transition: all 0.2s linear;
}
<div>test
</div>
Here's both at once because why not:
div {
display: flex;
align-items: center;
color: #ab9b8c;
font-size: 20px;
letter-spacing: 1.5px;
text-decoration: none;
height: 100%;
cursor: pointer;
transition: height 2s;
position: relative;
}
div::after {
content: '';
position: absolute;
bottom: -1px;
width: 0px;
height: 3px;
border-radius: 200px;
border: 0px solid #9f9182;
opacity: 0;
transition: all 0.2s linear;
}
div:hover::after {
width: 30px;
opacity: 1;
border: 1px solid #9f9182;
transition: all 0.2s linear;
}
<div>test
</div>
So on and so on
I'm trying to get my head around pseudo elements, but cannot seem to get a simple button animation to work with it.
On hover, I want a panel to go from bottom to top. Similar to the button found on this page (1st row, 2nd button).
From my understanding, using .btn:after will add any css after each .btn class. But then why doesn't this work?
.btn {
border: 1px solid #65bb39;
color: #fff;
background-color: #65bb39;
cursor: pointer;
padding: 25px 80px;
display: inline-block;
margin: 15px 30px;
text-transform: uppercase;
outline: none;
position: relative;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.btn:after {
content: '';
position: absolute;
z-index: -1;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
border: 1px solid #65bb39;
background-color: #fff;
}
*, *:after, *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
<div class="text">
<span class="btn">Test</span>
</div>
On hover, I want the border to turn #65bb39 and the block to fill white (from bottom to top).
Of course, any feedback on before and after is appreciated!
So will need to add a hover state to the btn:after and then transition css between the two states. See snippet below.
*, *:after, *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.btn {
color: #fff;
cursor: pointer;
padding: 25px 80px;
display: inline-block;
margin: 15px 30px;
text-transform: uppercase;
position: relative;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
}
.btn:hover{
color: #65bb39;
}
.btn:after, .btn:before {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0;
color: #65bb39;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
border: 1px solid #65bb39;
background-color: #fff;
}
.btn:before {
z-index: -2;
background-color: #65bb39;
height: 100%;
}
.btn:after {
z-index: -1;
}
.btn:hover:after {
height: 100%;
}
<div class="btn">Test</div>
I think this is what you're looking for:
body,
html {
height: 100%;
width: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
a {
color: white;
text-decoration: none;
font-weight: bold;
font-size: 1.25em;
text-align: center;
line-height: 75px;
}
.button {
height: 75px;
width: 200px;
position: absolute;
border: 1px solid #65bb39;
background: transparent;
transition: all .3s ease-in-out;
}
.button::after {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: #65bb39;
z-index: -1;
transition: all .3s ease-in-out;
}
.button:hover {
color: #65bb39;
}
.button:hover::after {
height: 0%;
}
.button:hover::before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: white;
z-index: -2;
}
Button
There you go:
.btn {
border: 3px solid #65bb39;
background: none;
color: #65bb39;
cursor: pointer;
padding: 25px 80px;
display: inline-block;
margin: 15px 30px;
text-transform: uppercase;
outline: none;
position: relative;
transition: all 0.3s;
}
.btn:hover {
color: #FFFFFF;
}
.btn:after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 0;
width: 100%;
background: #65bb39;
z-index: -1;
transition: all 0.3s;
}
.btn:hover:after {
height: 100%;
}
*,
*:after,
*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
<div class="text">
<span class="btn">Test</span>
</div>
Try this
.btn {
border: 2px solid #65bb39;
background: none;
color: #fff;
cursor: pointer;
padding: 25px 80px;
display: inline-block;
margin: 15px 30px;
text-transform: uppercase;
outline: none;
position: relative;
transition: all 0.3s;
}
.btn:hover {
color: #65bb39;
}
.btn:after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: #65bb39;
z-index: -1;
transition: all 0.4s;
}
.btn:hover:after {
height: 0%;
}
*,
*:after,
*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
<div class="text"><span class="btn">Test</span></div>
I am unsure of what I am doing wrong trying to get a transparent overlay to appear over an image on hover. Initially, I attempted a javascript approach, but that didn't work, so I figured I would try a more light-weight css approach.
Does anyone see why this is not working?
.section2-box {
display: inline-block;
width: 50%;
height: 50%;
border-bottom: 4px solid #FFF;
border-right: 4px solid #FFF;
box-sizing: border-box;
position: relative;
}
.fadeHover {
transition: all .35s ease;
-webkit-transition: all .35s ease;
transition-delay: 0.10s;
-webkit-transition-delay: 0.10s;
height: 100%;
width: 100%;
top: 0;
left: 0;
right: 0;
}
.fadeHover:hover .overlay {
background-color: rgba(0, 0, 0, 0.6);
z-index: 1;
height: 100%;
width: 100%;
top: 0;
left: 0;
right: 0;
position: absolute;
cursor: pointer;
}
.fadeHover-title {
font-family: 'Raleway', sans-serif;
font-weight: 600;
font-size: 1.3rem;
color: #FFF;
display: none;
}
.fadeHover-title.activeHover {
opacity: 1;
}
.fadeHover-description {
font-size: 1.1rem;
color: #FFF;
font-family: 'Open Sans', sans-serif;
display: none;
}
.fadeHover-description.activeHover {
opacity: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="section2-box fadehover" id="section2box3">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg/220px-Ash_Tree_-_geograph.org.uk_-_590710.jpg">
<div class="overlay">
<h2 class="fadeHover-title">Option 1</h2>
<h3 class="fadeHover-description">Description</h3>
</div>
</div>
Regardinf your question on the comment : change the text color of the element from a rgba with 0 alpha to a 1 alpha:
.section2-box {
display: inline-block;
width: 50%;
height: 50%;
border-bottom: 4px solid #FFF;
border-right: 4px solid #FFF;
box-sizing: border-box;
position: relative;
}
.fadeHover {
transition: all .35s ease;
-webkit-transition: all .35s ease;
transition-delay: 0.10s;
-webkit-transition-delay: 0.10s;
height: 100%;
width: 100%;
top: 0;
left: 0;
right: 0;
}
.fadeHover .overlay {
z-index: 1;
height: 100%;
width: 100%;
top: 0;
left: 0;
right: 0;
position: absolute;
cursor: pointer;
}
.fadeHover-title {
font-family: 'Raleway', sans-serif;
font-weight: 600;
font-size: 1.3rem;
color: rgba(255,255,255,0);
transition: color 0.5s;
}
.fadeHover:hover .fadeHover-title {
color: rgba(255,255,255,1);
}
.fadeHover-description {
font-size: 1.1rem;
color: rgba(255,0,0,0);
transition: color 0.5s;
}
.fadeHover:hover .fadeHover-description {
color: rgba(255,0,0,1);
}
<div class="section2-box fadeHover" id="section2box3">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Ash_Tree_-_geograph.org.uk_-_590710.jpg/220px-Ash_Tree_-_geograph.org.uk_-_590710.jpg">
<div class="overlay">
<h2 class="fadeHover-title">Option 1</h2>
<h3 class="fadeHover-description">Description</h3>
</div>
</div>
I'm doing a search box slide. What I need is that when you click on the magnifying glass, move the slide the "Castilian", text and that it is not fixed text and sarch see box below. It's possible? this is the best I could do ...
My code
try this css. This worked.
#wrap {
margin: 39px 60px;
display: inline-block;
position: relative;
/*float: right;*/
padding: 0;
position: relative;
}
input[type="text"] {
height: 60px;
font-size: 55px;
display: inline-block;
font-family: "Lato";
font-weight: 100;
border: none;
outline: none;
color: #555;
padding: 3px;
padding-right: 60px;
width: 0px;
position: relative;
top: 0;
right: 0;
background: none;
z-index: 3;
transition: width .4s cubic-bezier(0.000, 0.795, 0.000, 1.000);
cursor: pointer;
}
input[type="text"]:focus:hover {
border-bottom: 1px solid #BBB;
}
input[type="text"]:focus form {
width: 700px;
}
input[type="text"]:focus {
width: 700px;
z-index: 1;
border-bottom: 1px solid #BBB;
cursor: text;
}
input[type="submit"] {
height: 67px;
width: 63px;
display: inline-block;
color:red;
/*float: right;*/
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRFU1NT9fX1lJSUXl5e1dXVfn5+c3Nz6urqv7+/tLS0iYmJqampn5+fysrK39/faWlp////Vi4ZywAAABF0Uk5T/////////////////////wAlrZliAAABLklEQVR42rSWWRbDIAhFHeOUtN3/ags1zaA4cHrKZ8JFRHwoXkwTvwGP1Qo0bYObAPwiLmbNAHBWFBZlD9j0JxflDViIObNHG/Do8PRHTJk0TezAhv7qloK0JJEBh+F8+U/hopIELOWfiZUCDOZD1RADOQKA75oq4cvVkcT+OdHnqqpQCITWAjnWVgGQUWz12lJuGwGoaWgBKzRVBcCypgUkOAoWgBX/L0CmxN40u6xwcIJ1cOzWYDffp3axsQOyvdkXiH9FKRFwPRHYZUaXMgPLeiW7QhbDRciyLXJaKheCuLbiVoqx1DVRyH26yb0hsuoOFEPsoz+BVE0MRlZNjGZcRQyHYkmMp2hBTIzdkzCTc/pLqOnBrk7/yZdAOq/q5NPBH1f7x7fGP4C3AAMAQrhzX9zhcGsAAAAASUVORK5CYII=) center center no-repeat;
text-indent: -10000px;
border: none;
position: absolute;
top: 0;
right: 0;
z-index: 2;
cursor: pointer;
opacity: 0.4;
cursor: pointer;
transition: opacity .4s ease;
}
input[type="submit"]:hover {
opacity: 0.8;
}
All right? I'm having problems with an effect on CSS. Everything works perfectly until I put the code inside another div, and has a background that is not transparent. Look at the example below:
body {
background: #2ecc71;
padding:0;
margin:0;
}
#bg{
background: #000;
}
.container-button {
padding: 10em;
margin: 0 auto;
width: 1170px;
text-align: center;
display: block;
overflow: hidden;
}
/* GENERAL BUTTON STYLING */
.btn-more-info{
display:block;
overflow: hidden;
text-align: center;
display: inline-block;
float: left;
}
.btn-more-info a,
.btn-more-info a::after {
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
test-ident: -9999px;
text-decoration: none;
}
.btn-more-info a {
background: none;
border: 2px solid #fff;
border-radius: 5px;
color: #fff;
display: block;
font-size: 14px;
font-weight: bold;
padding: 20px 50px;
position: relative;
text-transform: uppercase;
}
.btn-more-info a::before,
.btn-more-info a::after {
background: #fff;
content: '';
position: absolute;
z-index: -1;
}
.btn-more-info a:hover {
color: #2ecc71;
}
/* BUTTON EFFECT */
.btn-effect {
overflow: hidden;
}
.btn-effect::after {
/*background-color: #f00;*/
height: 100%;
left: -35%;
top: 0;
transform: skew(50deg);
transition-duration: 0.6s;
transform-origin: top left;
width: 0;
}
.btn-effect:hover:after {
height: 100%;
width: 135%;
}
.btn-send{
overflow: hidden;
text-align: center;
clear: both;
}
.btn-send a,
.btn-send a::after {
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
test-ident: -9999px;
text-decoration: none;
}
.btn-send a {
background: none;
border: 2px solid #353B4C;
border-radius: 5px;
color: #353B4C;
display: inline-block;
font-size: 14px;
font-weight: bold;
padding: 20px 50px;
position: relative;
text-transform: uppercase;
}
.btn-send a::before,
.btn-send a::after {
background: #353B4C;
content: '';
position: absolute;
z-index: -1;
}
.btn-send a:hover {
color: #FFF;
}
<div id="bg">
<div class="container-button">
<div class="btn-more-info">
Continue lendo
</div>
<div class="btn-send">
Enviar mensagem
</div>
</div>
</div>
You see, if you remove the id="bg" effect functions normally.
Can anyone help me?
Thank U!
The problem is on the z-index of the :before and :after.
Try this:
.btn-more-info a::before,
.btn-more-info a::after {
background: #fff;
content: '';
position: absolute;
z-index: 0;
}
Also increase the z-index on the text inside the button.