Underline transitions on hover give thick border - css

I am trying to create an underline transition for my menu items. I followed the answer on this post but with small difference :
On the answer it uses for setting the border css :
a { text-decoration: none; display: inline-block; }
a:after {
content: '';
display: block;
border-bottom: 1px solid blue;
width: 0;
-webkit-transition: 0.5s ease;
transition: 0.5s ease;
}
a:hover:after { width: 100%; }
<a>A link with an animated bottom border</a>
For my example i'm using :
a { text-decoration: none; display: inline-block; }
a:after {
content: '';
display: block;
width: 0px;
border-bottom-width: 1px;
border-style: solid;
border-color: rgb(21 19 25);
-webkit-transition: 0.5s ease;
transition: 0.5s ease;
}
a:hover:after { width: 100%; }
<a>A link with an animated bottom border</a>
While this should give the same result, i'm getting a thicker border and part of it is already displayed
I need to use second example syntax as i'm using Tailwindcss and can't find a way to use border-bottom shorthand with different properties, i expect to get the same result as the first example
Update :
In addition to the accepted answer, this is how to make it work with tailwindCSS, this is the translated answer from css to Tailwind
#apply after:block
after:w-0
after:border-0
after:border-b
after:border-solid
after:border-b-blue
after:transition-all
after:duration-200
after:ease-linear
after:content-[''];

Below you have a working solution with the same result as your first snippet.
I am not familiar with Tailwindcss, but replacing these might work for you:
border-style with border-bottom-style
border-color with border-bottom-color
a { text-decoration: none; display: inline-block; }
a:after {
content: '';
display: block;
width: 0px;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(21 19 25);
-webkit-transition: 0.5s ease;
transition: 0.5s ease;
}
a:hover:after { width: 100%; }
<a>A link with an animated bottom border</a>

Related

How to show ::after content on the same line as an <a> element?

Have the following CSS that underlines a URL as desired:
.underline {
text-decoration: none;
position: relative;
}
.underline:after {
position: absolute;
content: '';
height: 2px;
bottom: -4px;
margin: 0 auto;
left: 0;
right: 0;
width: 50%;
background: green;
-o-transition: .5s;
-ms-transition: .5s;
-moz-transition: .5s;
-webkit-transition: .5s;
transition: .5s;
}
.underline:hover:after {
width: 80%;
background: orange;
}
On my page, some URLs are intra-page links, and the above works fine.
Other URLs are external links and, when selected, leave the page.
To signal the user that selecting the link will leave the page, I want to put a symbol after an anchor statement.
For example Wikipedia
So, have created an additional statement for URLs that are external links and include target="_blank"
a[target="_blank"]::after {
content: "\279A";
}
But in that implementation, the symbol "\279A" appears on a new line, which is not what I want.
The follow fails:
a[target="_blank"]::after {
content: "\279A";
display: inline-block;
}
My question is: for a statement that looks like this:
<a class="underline" href="https://https://en.wikipedia.org/wiki/Main_Page" target="_blank">Wikipedia</a>
how to modify the CSS to remove the resulting line-break and keep the leave-page symbol adjacent to the link?
You have two separate selectors that apply styles to the same ::after pseudo-element. Both a[target="_blank"]::after and .underline:after are targeting the same thing. You can remove the positioning properties from .underline:after and the icon will be inline, or you can move the first styles to ::before:
.underline {
text-decoration: none;
position: relative;
}
.underline::before { /* I changed this to ::before from :after */
position: absolute;
content: '';
height: 2px;
bottom: -4px;
margin: 0 auto;
left: 0;
right: 0;
width: 50%;
background: green;
-o-transition: .5s;
-ms-transition: .5s;
-moz-transition: .5s;
-webkit-transition: .5s;
transition: .5s;
}
.underline:hover::before {
width: 80%;
background: orange;
}
a[target="_blank"]::after {
content: "\279A";
}
<a class="underline" href="https://https://en.wikipedia.org/wiki/Main_Page" target="_blank">Wikipedia</a>

CSS: Animated button shown only when hovering image

I want to create a button that is hidden initially but then displays over an image when the image is hovered. I want the button to animate from the top of the image(initially hidden) to the middle(displayed on hover). Here is an example, scroll to the "latest from blog" section and hover the image.
The problems I'm having:
I want the button hidden completely when the image is not hovered. Setting the opacity to zero doesn't fully hide it and if the user hovers over the hidden button it twitches.
If the user hovers the image, the button animates down over the image like it should. I want it to animate back up and disappear when the user stops hovering.
I've used CSS filter and a transition to darken the image on hover. When the button animates down over the image on hover the image is still dark like it should be, but when the user hovers directly over the newly displayed button the image goes back to it's normal brightness. I want the image to stay dark (like in the example) when the user is directly over the button.
Here is my code. How can I make this button hover effect exactly like it is in the first example I showed?
You should really show us the code without react, as this would be a lot easier for everyone to check and debug. Regardless, I went to your source, and copied all the CSS used from the content given. It all activates when you hover over div.entry-image-attachment.
Pure CSS
#submit,
button,
.button,
input[type=submit] {
border: 0;
text-transform: uppercase;
cursor: pointer;
font-family: inherit;
font-weight: 400!important;
line-height: 1;
margin: 0;
position: relative;
text-decoration: none;
text-align: center;
display: inline-block;
padding-top: .9375em;
padding-right: 1.875em;
padding-bottom: 1em;
padding-left: 1.875em;
font-size: .875em;
background-color: #2ecc71;
border-color: #2ecc71;
transition: all .5s ease 0s;
-webkit-transition: all .5s ease 0s;
-moz-transition: all .5s ease 0s;
color: #fff;
-webkit-border-radius: 2px;
border-radius: 2px;
}
.text-center {
text-align: center!important;
}
.trans-button {
background-color: transparent!important;
font-weight: bolder;
border-width: 1px;
border-style: solid;
}
.entry-image {
position: relative;
margin: 10px 0 15px;
}
.nd-content {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
-webkit-transition: all .5s ease;
transition: all .5s ease;
}
.nd-content_inner {
display: table;
width: 100%;
height: 100%;
}
.nd-content_inner1 {
display: table-cell;
width: 100%;
height: 100%;
vertical-align: middle;
}
.nd-title {
position: relative;
top: -150px;
opacity: 0;
margin: 0 0 30px;
-webkit-transition: all .3s ease .01s;
transition: all 1s ease .01s; /*Animation happens with this*/
}
.button.white.trans-button {
color: #fff;
}
.entry-image-attachment:hover .nd-title {
-webkit-transition: all .5s cubic-bezier(1, -.53, .405, 1.425) .01s;
transition: all .5s cubic-bezier(1, -.53, .405, 1.425) .01s;
}
.entry-image-attachment:hover .nd-icon,
.entry-image-attachment:hover .nd-content,
.entry-image-attachment:hover .nd-title {
opacity: 1;
top: 0;
}
.button.trans-button {
padding: 15px;
}
#submit.white,
button.white,
.button.white,
input[type=submit].white {
background-color: #fff;
border-color: #fff;
transition: all .5s ease 0s;
-webkit-transition: all .5s ease 0s;
-moz-transition: all .5s ease 0s;
color: #333;
-webkit-border-radius: 2px;
border-radius: 2px;
}
.entry-image-attachment:hover .nd-icon,
.entry-image-attachment:hover .nd-content,
.entry-image-attachment:hover .nd-title {
opacity: 1;
top: 0;
}
.entry-image-attachment:hover .nd-content {
background: rgba(0, 0, 0, .5);
}
<div class="entry-image">
<div class="entry-image-attachment" style="max-height:200px;overflow:hidden;">
<img src="http://rosette.leetheme.com/wp-content/uploads/2014/12/02.jpg" width="296" height="180" />
<div class="nd-content text-center">
<div class="nd-content_inner">
<div class="nd-content_inner1">
<div class="button trans-button white nd-title"><span>Read more</span></div>
</div>
</div>
</div>
</div>
</div>

How to create button scaling effect in CSS?

I need a button whose after selector expands and gets disappeared when clicked. I need this effect via CSS.
When i click this button it's after selector expands.
Like
#button::after{
transform: scale(2);
}
But this is not happening for me. Please help me. When clicked the after selector button should expand then should disappear. In a nutshell, i need button scaling effect.
Do you mean something like this?
As far as I know you can't get an onclick event with CSS only and without using JavaScript. You can use :active, but this will only apply the style when the mouse button is held down. See Bojangles answer on "Can I have an Onclick effect in CSS".
#button {
display: block;
border: none;
position: relative;
color: red;
background-color: white;
font-size: 30px;
padding: 15px 30px;
}
#button:after {
content: '';
position: absolute;
display: block;
height: 100%;
width: 100%;
top: 0;
left: 0;
border: 4px solid red;
color: black;
font-size: 8px;
opacity: 1;
transition: transform .3s ease, opacity .5s ease;
}
#button:active:after {
transform: scale(5);
opacity: 0;
}
<button id="button">BUTTON</button>
**The code snippet is built upon on benedikt's answer.
#button:after's border color is set to transparent, adds border-color during the animation. this creates the illusion that it disappears. I hope this helps.
#button {
display: block;
border: 4px solid red;
position: relative;
color: red;
background-color: white;
font-size: 30px;
padding: 15px 30px;
}
#button:after {
content: '';
position: absolute;
display: block;
width:100%;
height:100%;
top:0;
left:0;
border: 4px solid transparent;
color: black;
font-size: 8px;
opacity: 1;
transition: transform 0.3s ease, opacity 0.5s ease, border-color 0.1s ease;
}
#button:active:after {
transform: scale(2);
border-color:red;
opacity: 0;
}
<button id="button">BUTTON</button>

Changing border-bottom to border-top

I want to have a transistion on my menu list when hovered but I want to change the border-bottom to border-top.
How can I do this?
.sliding-middle-out {
display: inline-block;
position: relative;
padding-bottom: 3px;
}
.sliding-middle-out:after {
content: '';
display: block;
margin: auto;
height: 3px;
width: 0px;
background: transparent;
transition: width .5s ease, background-color .5s ease;
}
.sliding-middle-out:hover:after {
width: 100%;
background: blue;
}
<li class="scroll sliding-middle-out">Features</li>
You can use the :before pseudo element instead of the :after pseudo element so the line is displayed on top of (before) your link:
.sliding-middle-out {
display: inline-block;
position: relative;
padding-bottom: 3px;
}
.sliding-middle-out:before {
content: '';
display: block;
margin: auto;
height: 3px;
width: 0px;
background: transparent;
transition: width .5s ease, background-color .5s ease;
}
.sliding-middle-out:hover:before {
width: 100%;
background: blue;
}
<li class="scroll sliding-middle-out">Features</li>
Note that the line isn't made with the border property but with the background of the pseudo element

Activating div while hovering over underlaying div - CSS transition not working

First of all, I'm sorry if this question was already answered but I couldn't find it anywhere.
I'm trying to get a smooth transition when hovering over a div. On top of this div is another div, which gets visible when hovering. The transition didn't seem to do the trick, so how can I pull this off? (jquery instead of CSS, or other/better code?)
Maybe there's another way of doing this, I hope you guys can help me.
HTML:
<ul>
<li>
<div class="hover">
<a href="#">
<p>Test</p>
</a>
</div>
<img src="#" alt="img" />
<div class="text">
<p>Test</p>
</div>
</li>
</ul>
CSS:
body { background-color: #eee;
}
ul { margin: 0;
padding: 0;
list-style: none;}
ul li { width: 30.33%;
height: auto;
margin-right: 3%;
padding: 5px;
background-color: #fff;
float: left;
position: relative;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;}
ul li img { width: 100%;
max-height: 100%;
z-index: 1;
background-color: #ddd;
border: 0;}
.text { width: 100%;
padding-top: 7%;}
.text p { margin: 0 10px;
padding-bottom: 7%;}
.hover { height: 100%;
background-color: #333;
position: absolute;
top: 0;
left: 0;
right: 0;
display: none;}
.hover a { width:100%;
height: 100%;
margin: 0;
padding: 25px;
display: block;
color: #fff;
text-decoration: none;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;}
ul li:hover > .hover { display: block;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;}
Here's the code: http://jsfiddle.net/HAFEx/
Thanks in advance!
A couple things need to be changed. Firstly, you can't animate the display property, so you should toggle opacity on hover instead.
Secondly, you should apply the transition on .hover, not just on parent:hover .hover so that it transitions both ways.
Using both of those improvements (and some formatting of your code) you get this result
.hover {
transition: all 0.2s ease;
opacity:0;
... Other properties ...
}
display:block can't be afected by a transition.
Instead use opacity.
.hover { height: 100%;
background-color: #333;
position: absolute;
top: 0;
left: 0;
right: 0;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
opacity:0;
}
ul li:hover > .hover{
display: block;
opacity:1;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;
}
http://jsfiddle.net/Rjq3y/
You cannot transition css display. Try opacity.
http://jsfiddle.net/HAFEx/2/
ul li:hover .hover {
opacity:1;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;
}
You can also jquery to animate the display:none property.
$("li").mouseover(function(){
$(".hover").fadeIn(1000);
});
$(".hover").mouseout(function(){
$(".hover").fadeOut(1000);
});
Check out this codepen.
http://codepen.io/anon/pen/rqozA
The display property is a number or hexadecimal value, so it cannot be tweened. In this circumstance, you can't simply have the hover state opacity: 0.
Two work arounds are Javascript (messy) and using CSS Keyframe animations. http://hschwarz77.wordpress.com/2013/10/16/css-transition-from-display-none-to-display-block-on-hover/
To the best of my knowledge, these are the only solutions to have the div completely hidden (and unusable...visibility:hidden occupies the space) and fade in.

Resources