Smooth CSS transition from position relative to position absolute with :hover::after - html

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

Related

How can I skew outline of a focused element?

I have a customized button/link element that transforms the said element to look like this:
Problem I'm having is that when the button is focused using keyboard the outline is not transformed along the borders of the element. I've also tried using box-shadow, with same results. Is there a proper way to transform outline, like I did with the element itself?
.button {
font-family: $brand-font;
font-weight: 900;
transition: color $transition-duration ease-out;
-webkit-appearance: none;
-moz-appearance: none;
display: inline-block;
text-align: center;
max-width: 320px;
min-width: 200px;
height: 40px;
line-height: 40px;
position: relative;
border: none !important;
font-size: 1.4rem;
z-index: 0;
padding: 0 1.8rem;
background-color: transparent;
color: $primary-blue;
cursor: pointer;
&:visited {
border: none !important;
}
&.skewOnHover {
color: $secondary-blue;
}
& > svg {
vertical-align: middle;
}
&:focus {
outline: 2px solid $primary-blue;
// box-shadow: 0 0 0 2px $primary-blue;
}
&::before {
content: ""; display: block;
display: block;
width: 100%; height: 100%;
top: -2px; left: -2px;
transition-property: border, background-color, transform;
transition-duration: $transition-duration;
transition-timing-function: ease-out;
position: absolute;
z-index: -1;
// regular (cyan background, blue text)
background-color: $secondary-blue;
border: 2px solid $secondary-blue;
transform: skew(-22.5deg);
}
&.skewOnHover {
&::before {
background-color: transparent;
transform: skew(22.5deg);
}
}
Apply the outline to skewed element:
&:focus:before {
outline: 2px solid red;
}
and reset the outline of button:
.button:focus {
outline: none;
}
.button {
font-weight: 900;
transition: color 0.3s ease-out;
-webkit-appearance: none;
-moz-appearance: none;
display: inline-block;
text-align: center;
max-width: 320px;
min-width: 200px;
height: 40px;
line-height: 40px;
position: relative;
border: none !important;
font-size: 1.4rem;
z-index: 0;
padding: 0 1.8rem;
background-color: transparent;
color: blue;
cursor: pointer;
}
.button:visited {
border: none !important;
}
.button.skewOnHover {
color: dodgerblue;
}
.button>svg {
vertical-align: middle;
}
.button:focus {
outline: none;
}
.button:focus:before {
outline: 2px solid red;
}
.button::before {
content: "";
display: block;
display: block;
width: 100%;
height: 100%;
top: -2px;
left: -2px;
transition-property: border, background-color, transform;
transition-duration: 0.3s;
transition-timing-function: ease-out;
position: absolute;
z-index: -1;
background-color: dodgerblue;
border: 2px solid dodgerblue;
transform: skew(-22.5deg);
}
.button.skewOnHover::before {
background-color: transparent;
transform: skew(22.5deg);
}
<button class="button">button</button>

I can't get a transition effect inside a dropdown to work [duplicate]

This question already has answers here:
Transitions on the CSS display property
(37 answers)
Closed 3 years ago.
I'm trying to transition effect for my menu's dropdown, but unlike the other cases, I can't manage to get it work.
I've search lots of theards around here and over google as well. I found no solution.
Here's my code:
.dropdown2 {
position: relative;
display: inline-block;
}
.dropdown-content2 {
display: none;
position: absolute;
background-color: #e1e1e1;
color: #000;
min-width: 150px;
height: 220px;
z-index: 999;
font-size: 20px;
margin-right: -10px;
top: 34px;
transition: height 2s;
}
.dropdown-content2 a {
padding: 12px 16px;
text-decoration: none;
display: block;
border-bottom: 5px solid white;
}
.dropdown2:hover .dropdown-content2 {
display: block;
}
.dropdown2:hover .dropbtn2 {
background-color: #e1e1e1;
}
HTML:
<div class="menu_option dropdown2">articles
<div class="dropdown-content2">
news
reviews
guides
art
</div>
</div>
And it doesn't work.
try like this.. in display none and block transition effect not working.. so now i changed opacity
HTML
<div class="menu_option dropdown2">כל הכתבות
<div class="dropdown-content2">
news
reviews
guides
art
</div>
</div>
css
.dropdown2 {
position: relative;
display: inline-block;
}
.dropdown-content2 {
opacity:0;
visibility:hidden;
position: absolute;
background-color: #e1e1e1;
color: #000;
min-width: 150px;
height: 220px;
z-index: 999;
font-size: 20px;
margin-right: -10px;
top: 34px;
-webkit-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease
}
.dropdown-content2 a {
padding: 12px 16px;
text-decoration: none;
display: block;
border-bottom: 5px solid white;
}
.dropdown2:hover .dropdown-content2 {
opacity:1;
visibility:visible;
-webkit-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease
}
.dropdown2:hover .dropbtn2 {
background-color: #e1e1e1;
}
You can't transition from display: none to display: block.
Fortunately, in this case you don't need to. You only need to transition from height: 0 to height: 220px.
N.B. You also need to ensure that .dropdown-content2 has the style overflow: hidden to ensure that when the content of the parent element exceeds the height, it does not overflow the boundaries and reveal itself.
Working Example:
.dropdown2 {
position: relative;
display: inline-block;
}
.dropdown-content2 {
position: absolute;
background-color: #e1e1e1;
color: #000;
min-width: 150px;
z-index: 999;
font-size: 20px;
margin-right: -10px;
top: 34px;
overflow: hidden;
}
.dropdown-content2 a {
padding: 12px 16px;
text-decoration: none;
display: block;
border-bottom: 5px solid white;
}
.dropdown2 .dropdown-content2 {
height: 0;
transition: height 2s;
}
.dropdown2:hover .dropdown-content2 {
height: 220px;
}
.dropdown2:hover .dropbtn2 {
background-color: #e1e1e1;
}
<div class="menu_option dropdown2">articles
<div class="dropdown-content2">
news
reviews
guides
art
</div>
</div>

Hide :before on :hover button

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

Weird spaces between a tags

I'm making dropdown menu with HTML/CSS/JS. Entering five tags and adding "margin-top: 20px" it should make 20px spaces from top, but it makes bigger and smaller spaces - 24px from top, 28px from top, 28px from top...
I can't find the problem in my code. I was deleting margins, paddings on other classes. Any changes were unsuccessful.
HTML:
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn"><div class="cog"></div></button>
<div id="myDropdown" class="dropdown-content">
<div class="dop"></div>
Text
Text
Text
Text
Text
</div>
</div>
<script src="js/js-1_dropdown.js"></script>
CSS:
.dropbtn {
height: 34px;
width: 34px;
background: #f0f0f0;
border-radius: 3px;
border: none;
cursor: pointer;
transition: 0.3s ease;
-webkit-transition: 0.3s ease;
-moz-transition: 0.3s ease;
-o-transition: 0.3s ease;
}
.dropbtn:hover, .dropbtn:focus {
background: #ebebeb;
}
.dropdown {
position: relative;
display: inline-block;
margin-top: 100px;
margin-left: 100px;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #ffffff;
width: 140px;
border-radius: 3px;
left: -53px;
top: 48px;
}
.dropdown-content a {
color: #b7b7b7;
text-decoration: none;
display: block;
font-family: OpenSans-Regular;
font-size: 12px;
text-align: center;
padding-top: 20px;
position: relative;
margin: 0;
}
.dropdown-content a:hover {
color: #adadad;
}
.show {display:block;}
.cog {
height: 16px;
width: 16px;
position: absolute;
top: 9px;
left: 9px;
background: url(img/i-3_settings.png);
}
.dop {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 4px solid #ffffff;
position: absolute;
top: -4px;
left: 65px;
}
* {
outline: none;
}
Live - https://jsfiddle.net/qc8aempj/
Ričards.

Slide text search box is overwritten

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;
}