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>
Related
I am a beginner of HTML and CSS. I am learning web development recently and trying to make a simple website page. On that page, there will be two sidebars. One is left side bar, other one is right side bar. But when i click on left sidebar menu icon, it opens both left and right sidebar, but i want to open only left one. And when i click on right sidebar menu icon, it only opens right sidebar. What am i doing wrong here ?
html,
body {
overflow-x: hidden;
height: 100%;
}
body {
background: white;
padding: 0;
margin: 0;
font-family: tahoma;
}
body {
background-image: url(scene.jpg);
background-size: cover;
background-position: center;
}
.header {
display: block;
margin: 0 auto;
width: 100%;
max-width: 100%;
box-shadow: none;
background-color: #000000;
position: fixed;
height: 60px !important;
overflow: hidden;
z-index: 10;
}
.main {
margin: 0 auto;
display: block;
height: 100%;
margin-top: 60px;
}
.mainInner {
display: table;
height: 100%;
width: 100%;
text-align: center;
}
.sidebarMenu {
height: 100%;
position: fixed;
left: 0;
width: 250px;
margin-top: 60px;
transform: translateX(-250px);
transition: transform 250ms ease-in-out;
background: linear-gradient(180deg, #000000 0%, #3f5efb 100%);
}
.rightsidebarMenu {
height: 100%;
position: fixed;
right: 0;
width: 250px;
margin-top: 60px;
transform: translateX(250px);
transition: transform 250ms ease-in-out;
background: linear-gradient(180deg, #000000 0%, #3f5efb 100%);
}
.sidebarMenuInner {
margin: 0;
padding: 0;
border-top: 1px solid rgba (255, 255, 255, 0.10);
}
.rightsidebarMenuInner {
margin: 0;
padding: 0;
border-top: 1px solid rgba (255, 255, 255, 0.10);
}
.sidebarMenuInner li {
list-style: none;
color: white;
text-transform: uppercase;
font-weight: bold;
padding: 20px;
cursor: pointer;
border-bottom: 1px solid rgba (255, 255, 255, 0.10);
}
.rightsidebarMenuInner li {
list-style: none;
color: white;
text-transform: uppercase;
font-weight: bold;
padding: 20px;
cursor: pointer;
border-bottom: 1px solid rgba (255, 255, 255, 0.10);
}
.sidebarMenuInner li a {
text-transform: uppercase;
font-weight: bold;
cursor: pointer;
text-decoration: none;
color: white;
border: 2px;
}
.rightsidebarMenuInner li a {
text-transform: uppercase;
font-weight: bold;
cursor: pointer;
text-decoration: none;
color: white;
border: 2px;
}
.sidebarMenuInner li span {
display: block;
font-size: 14px;
color: rgba (255, 255, 255, 0.50);
}
.rightsidebarMenuInner li span {
display: block;
font-size: 14px;
color: rgba (255, 255, 255, 0.50);
}
input[type="checkbox"] {
transition: all 0.3s;
box-sizing: border-box;
display: none;
}
input[type="checkbox"] {
transition: all 0.3s;
box-sizing: border-box;
display: none;
}
input[type="checkbox"]:checked~.sidebarMenu {
transform: translateX(0);
}
input[type="checkbox"]:checked~.rightsidebarMenu {
transform: translateX(0);
}
.sidebarIconToggle {
transition: all 0.3s;
box-sizing: border-box;
cursor: pointer;
position: absolute;
z-index: 99;
height: 100%;
width: 100%;
top: 22px;
left: 35px;
height: 22px;
width: 22px;
}
.rightsidebarIconToggle {
transition: all 0.3s;
box-sizing: border-box;
cursor: pointer;
position: absolute;
z-index: 99;
height: 100%;
width: 100%;
top: 22px;
right: 35px;
height: 22px;
width: 22px;
}
.spinner {
transition: all 0.3s;
box-sizing: border-box;
position: absolute;
height: 3px;
width: 100%;
background-color: white;
}
.right.spinner {
transition: all 0.3s;
box-sizing: border-box;
position: absolute;
height: 3px;
width: 100%;
background-color: white;
}
.horizontal {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
.right.horizontal {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: right;
margin-top: 3px;
}
.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
}
.right.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: right;
}
.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
.right.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: right;
margin-top: 3px;
}
input[type="checkbox"]:checked~.sidebarIconToggle>.horizontal {
transition: all 0.3s;
box-sizing: border-box;
opacity: 0;
}
input[type="checkbox"]:checked~.sidebarIconToggle>.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(135deg);
margin-top: 8px;
}
input[type="checkbox"]:checked~.sidebarIconToggle>.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(-135deg);
margin-top: -8px;
}
input[type="checkbox"]:checked~.rightsidebarIconToggle>.right.horizontal {
transition: all 0.3s;
box-sizing: border-box;
opacity: 0;
}
input[type="checkbox"]:checked~.rightsidebarIconToggle>.right.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(135deg);
margin-top: 8px;
}
input[type="checkbox"]:checked~.rightsidebarIconToggle>.right.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(-135deg);
margin-top: -8px;
}
<div class="header"></div>
<input type="checkbox" class="openSidebarMenu" id="openSidebarMenu">
<label for="openSidebarMenu" class="sidebarIconToggle">
<div class="spinner diagonal part-1"></div>
<div class="spinner horizontal"></div>
<div class="spinner diagonal part-2"></div>
</label>
<div class="sidebarMenu">
<ul class="sidebarMenuInner">
<li>Munem Sohan <span>Web Developer</span></li>
<li><span>Company</span></li>
<li><span>Facebook</span></li>
<li><span>Twitter</span></li>
</ul>
</div>
<input type="checkbox" class="rightopenSidebarMenu" id="rightopenSidebarMenu">
<label for="rightopenSidebarMenu" class="rightsidebarIconToggle">
<div class="right spinner diagonal part-1"></div>
<div class="right spinner horizontal"></div>
<div class="right spinner diagonal part-2"></div>
</label>
<div class="rightsidebarMenu">
<ul class="rightsidebarMenuInner">
<li>Sohan <span>Web Developer</span></li>
<li><span>Sabbir</span></li>
<li><span>Sumi</span></li>
<li><span>Shovon</span></li>
</ul>
</div>
You need to add id with checkbox, so it can apply checkbox uniquely for opening toggle
html,
body {
overflow-x: hidden;
height: 100%;
}
body {
background: white;
padding: 0;
margin: 0;
font-family: tahoma;
}
body {
background-image: url(scene.jpg);
background-size: cover;
background-position: center;
}
.header {
display: block;
margin: 0 auto;
width: 100%;
max-width: 100%;
box-shadow: none;
background-color: #000000;
position: fixed;
height: 60px !important;
overflow: hidden;
z-index: 10;
}
.main {
margin: 0 auto;
display: block;
height: 100%;
margin-top: 60px;
}
.mainInner {
display: table;
height: 100%;
width: 100%;
text-align: center;
}
.sidebarMenu {
height: 100%;
position: fixed;
left: 0;
width: 250px;
margin-top: 60px;
transform: translateX(-250px);
transition: transform 250ms ease-in-out;
background: linear-gradient(180deg, #000000 0%, #3f5efb 100%);
}
.rightsidebarMenu {
height: 100%;
position: fixed;
right: 0;
width: 250px;
margin-top: 60px;
transform: translateX(250px);
transition: transform 250ms ease-in-out;
background: linear-gradient(180deg, #000000 0%, #3f5efb 100%);
}
.sidebarMenuInner {
margin: 0;
padding: 0;
border-top: 1px solid rgba (255, 255, 255, 0.10);
}
.rightsidebarMenuInner {
margin: 0;
padding: 0;
border-top: 1px solid rgba (255, 255, 255, 0.10);
}
.sidebarMenuInner li {
list-style: none;
color: white;
text-transform: uppercase;
font-weight: bold;
padding: 20px;
cursor: pointer;
border-bottom: 1px solid rgba (255, 255, 255, 0.10);
}
.rightsidebarMenuInner li {
list-style: none;
color: white;
text-transform: uppercase;
font-weight: bold;
padding: 20px;
cursor: pointer;
border-bottom: 1px solid rgba (255, 255, 255, 0.10);
}
.sidebarMenuInner li a {
text-transform: uppercase;
font-weight: bold;
cursor: pointer;
text-decoration: none;
color: white;
border: 2px;
}
.rightsidebarMenuInner li a {
text-transform: uppercase;
font-weight: bold;
cursor: pointer;
text-decoration: none;
color: white;
border: 2px;
}
.sidebarMenuInner li span {
display: block;
font-size: 14px;
color: rgba (255, 255, 255, 0.50);
}
.rightsidebarMenuInner li span {
display: block;
font-size: 14px;
color: rgba (255, 255, 255, 0.50);
}
input[type="checkbox"] {
transition: all 0.3s;
box-sizing: border-box;
display: none;
}
input[type="checkbox"] {
transition: all 0.3s;
box-sizing: border-box;
display: none;
}
input[type="checkbox"]#openSidebarMenu:checked~.sidebarMenu {
transform: translateX(0);
}
input[type="checkbox"]#rightopenSidebarMenu:checked~.rightsidebarMenu {
transform: translateX(0);
}
.sidebarIconToggle {
transition: all 0.3s;
box-sizing: border-box;
cursor: pointer;
position: absolute;
z-index: 99;
height: 100%;
width: 100%;
top: 22px;
left: 35px;
height: 22px;
width: 22px;
}
.rightsidebarIconToggle {
transition: all 0.3s;
box-sizing: border-box;
cursor: pointer;
position: absolute;
z-index: 99;
height: 100%;
width: 100%;
top: 22px;
right: 35px;
height: 22px;
width: 22px;
}
.spinner {
transition: all 0.3s;
box-sizing: border-box;
position: absolute;
height: 3px;
width: 100%;
background-color: white;
}
.right.spinner {
transition: all 0.3s;
box-sizing: border-box;
position: absolute;
height: 3px;
width: 100%;
background-color: white;
}
.horizontal {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
.right.horizontal {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: right;
margin-top: 3px;
}
.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
}
.right.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: right;
}
.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 3px;
}
.right.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
position: relative;
float: right;
margin-top: 3px;
}
input[type="checkbox"]#openSidebarMenu:checked~.sidebarIconToggle>.horizontal {
transition: all 0.3s;
box-sizing: border-box;
opacity: 0;
}
input[type="checkbox"]#openSidebarMenu:checked~.sidebarIconToggle>.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(135deg);
margin-top: 8px;
}
input[type="checkbox"]#openSidebarMenu:checked~.sidebarIconToggle>.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(-135deg);
margin-top: -8px;
}
input[type="checkbox"]#rightopenSidebarMenu:checked~.rightsidebarIconToggle>.right.horizontal {
transition: all 0.3s;
box-sizing: border-box;
opacity: 0;
}
input[type="checkbox"]#rightopenSidebarMenu:checked~.rightsidebarIconToggle>.right.diagonal.part-1 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(135deg);
margin-top: 8px;
}
input[type="checkbox"]#rightopenSidebarMenu:checked~.rightsidebarIconToggle>.right.diagonal.part-2 {
transition: all 0.3s;
box-sizing: border-box;
transform: rotate(-135deg);
margin-top: -8px;
}
<div class="header"></div>
<input type="checkbox" class="openSidebarMenu" id="openSidebarMenu">
<label for="openSidebarMenu" class="sidebarIconToggle">
<div class="spinner diagonal part-1"></div>
<div class="spinner horizontal"></div>
<div class="spinner diagonal part-2"></div>
</label>
<div class="sidebarMenu">
<ul class="sidebarMenuInner">
<li>Munem Sohan <span>Web Developer</span></li>
<li><span>Company</span></li>
<li><span>Facebook</span></li>
<li><span>Twitter</span></li>
</ul>
</div>
<input type="checkbox" class="rightopenSidebarMenu" id="rightopenSidebarMenu">
<label for="rightopenSidebarMenu" class="rightsidebarIconToggle">
<div class="right spinner diagonal part-1"></div>
<div class="right spinner horizontal"></div>
<div class="right spinner diagonal part-2"></div>
</label>
<div class="rightsidebarMenu">
<ul class="rightsidebarMenuInner">
<li>Sohan <span>Web Developer</span></li>
<li><span>Sabbir</span></li>
<li><span>Sumi</span></li>
<li><span>Shovon</span></li>
</ul>
</div>
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
I want to make a CSS animation to open a transparent background from the center to the border (right and left) and leave the border red with text red and without any background.
Is it possible to do? I think I made a mistake with the class "bottone" but I don't know where!
The button needs to be like this, but with the colors inverted:
.bottone {
background: red;
box-sizing: border-box;
appearance: none;
color: #fff;
border: 2px solid red;
cursor: pointer;
display: inline-block;
position: relative;
align-self: center;
font-size: 1rem;
font-weight: 400;
line-height: 1;
margin: 20px;
padding: 1.2em 2.8em;
text-decoration: none;
text-align: center;
text-transform: uppercase;
font-family: 'Montserrat', sans-serif;
font-weight: 700;
position: relative;
overflow: hidden;
z-index: 1;
transition: color 150ms ease-in-out;
}
.bottone:after {
content: '';
position: absolute;
display: block;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 0%;
height: 100%;
background: red;
z-index: -1;
transition: width 150ms ease-in-out;
}
.bottone:hover {
color: red;
}
.bottone:hover:after {
width: 110%;
}
<a class="bottone">example</a>
Here's another attempt:
.bottone {
background: transparent;
box-sizing: border-box;
appearance: none;
color: red;
border: 2px solid red;
cursor: pointer;
display: inline-block;
position: relative;
align-self: center;
font-size: 1rem;
font-weight: 400;
line-height: 1;
margin: 20px;
padding: 1.2em 2.8em;
text-decoration: none;
text-align: center;
text-transform: uppercase;
font-family: 'Montserrat', sans-serif;
font-weight: 700;
position: relative;
overflow: hidden;
z-index: 1;
transition: color 150ms ease-in-out;
}
.bottone:after {
content: '';
position: absolute;
display: block;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 0%;
height: 100%;
background: red;
z-index: -1;
transition: width 150ms ease-in-out;
}
.bottone:hover {
color: #fff;
}
.bottone:hover:after {
width: 110%;
}
<a class="bottone">example</a>
Instead of "opening a transparent background", consider "moving two elements to reveal a transparent background". One idea is to use two pseudo-elements, :before and :after, that recede to opposite sides of the box.
In my example, one is left:0 and the other is right:0.
Their widths both transition from 50% to 0.
body {
background-color: lightgreen;
}
.bottone {
background: transparent;
box-sizing: border-box;
appearance: none;
color: white;
border: 2px solid red;
cursor: pointer;
display: inline-block;
position: relative;
align-self: center;
font-size: 1rem;
font-weight: 400;
line-height: 1;
margin: 20px;
padding: 1.2em 2.8em;
text-decoration: none;
text-align: center;
text-transform: uppercase;
font-family: 'Montserrat', sans-serif;
font-weight: 700;
position: relative;
overflow: hidden;
z-index: 1;
transition: color 150ms ease-in-out;
}
.bottone:hover {
color: red;
}
.bottone:before,
.bottone:after {
content: '';
position: absolute;
display: block;
top: 0;
width: 50%;
height: 100%;
background: red;
z-index: -1;
transition: width 150ms ease-in-out;
}
.bottone:before {
left: 0;
}
.bottone:after {
right: 0;
}
.bottone:hover:before,
.bottone:hover:after {
width: 0;
}
<a class="bottone">example</a>
Color need to be swapped.
pseudo size needs also to be set and reset on hover.
CSS commented
.bottone {
background: transparent;
box-sizing: border-box;
appearance: none;
color: white;/* inverted*/
border: 2px solid red;
cursor: pointer;
display: inline-block;
position: relative;
align-self: center;
font-size: 1rem;
font-weight: 400;
line-height: 1;
margin: 20px;
padding: 1.2em 2.8em;
text-decoration: none;
text-align: center;
text-transform: uppercase;
font-family: 'Montserrat', sans-serif;
font-weight: 700;
position: relative;
overflow: hidden;
z-index: 1;
transition: color 150ms ease-in-out;
}
.bottone:after {
content: '';
position: absolute;
display: block;
top: 0;
left: 50%;
width: 0%;
height: 100%;
width: 110%;/* moved here */
background: red;
transform: translateX(-50%);
z-index: -1;
transition: width 150ms ease-in-out;
}
.bottone:hover {
color: red;/* inverted */
}
.bottone:hover:after {
width: 0;/* reset here */
}
<a class="bottone">example</a>
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;
}