Fade in border on hover - css

I want to fade in a border on hover. I have the following but it starts off as nothing then goes to a 1px grey line (grey is default color) and then eventually goes to a 2px red line.
What am I going wrong?
a{
border-bottom: none;
transition: border-bottom 1s;
}
a:hover{
border-bottom: 2px solid red;
}
<a href='#'>hover here</a>

When an element has no border, then you add on hover you face a few issues such as page moving, drawing border from scratch etc
Solution: Try setting border to transparent first, so it's there but cannot be seen:
a {
border-bottom: 2px solid transparent; /* <- here */
transition: border-bottom 1s;
text-decoration: none; /* I added this for clarity of effect */
}
a:hover {
border-bottom: 2px solid red;
}
testing border
Edit
Actually, you don't need to declare the whole border again, just change the color:
a:hover {
border-color: red; /* <-- just change the color instead */
}

You need to provide a border by default to the hyperlink, which should be transparent in color. Later on hover, you may modify it's color. Leave the rest on the transition property.
See it yourself.
a {
border-bottom: 2px solid transparent;
transition: border-bottom 1s;
text-decoration: none;
}
a:hover {
border-bottom-color: red;
}
Demo Hyperlink
Cheers!

Why this happens
You get this because of your transition and the initial value of your element. All elements have default values, even when those aren't defined by you. For instance, <div> elements always have display: block per default and <b> elements have font-weight: bold per default.
Similarly, your <a> tag has border-bottom-color: rgb(0, 0, 0). This is true even when the thickness of the border is zero.
In chrome, you can see all of this in the "computed" section of the "Elements" tab:
So when the transition starts, it's going to gradually change the color from black to the red you defined.
How to fix
What you need to do is to override that default values, with your own. This is to prevent it from starting off as black.
a{
border-bottom: 2px solid transparent;
transition: border-bottom 1s;
}
a:hover{
border-bottom: 2px solid red;
}
A tip is to always define the same properties for an element "before" a hover and "during" one. Another thing you should be aware of is that using none as the initial value usually won't give you the behavior you want. Transitions need a numerical value as a start-off point (e.g 0).

Related

How to make a GtkButton fully invisible

I have a grid of buttons in which it is easier for me to make some buttons invisible then not creating them. They have no function and are only placeholder. They have a styleclass attached to them called transparent. I was mostly able to hide them but there is still a line around them left that is not fully transparent. It kinda looks like the shadow of the button or something. I tried hiding them with the following CSS:
.transparent {
background: transparent;
outline-color: transparent;
border-color: transparent;
color: transparent;
}
How can I hide that last bit of the buttons? They are ToggleButtons. Not sure if that is important
Even though I am using GTK3 I looked at the documentation for GTK4 and there I found the right property. It was indeed a shadow and it can be removed with: box-shadow: none;
My solution now looks like:
.transparent {
background: transparent;
outline-color: transparent;
border-color: transparent;
color: transparent;
box-shadow: none;
}
try this:
.transparent {
opacity: 0;
}
You could use display: none or visibility: hidden.
display: none removes the element from the page, and other elements can take its place, whereas visibility: hidden leaves the element in its place and just hides it.

CSS – Transition on border-bottom not working

I'm wanting to have a border bottom transition on my header navigation when the cursor hovers over the links. It was working when I first implemented this, but after adding some more code, I can't get this to work whatsoever.
My CSS looks like this:
a:link,
a:visited {
color: #1c2234;
text-decoration: none;
padding-bottom: 20px;
border-bottom: 3px solid transparent;
-webkit-transition: border-bottom 0.2s, color 0.2s;
transition: border-bottom 0.2s, color 0.2s;
}
a:hover,
a:active {
color: #555;
border-bottom: 3px solid #1c2234;
}
Here's a picture of the header
I know that a common issue with this is not setting the border-bottom prior to hover, but I did that already and set it to transparent. The color changes upon hover, but the border isn't showing up. Any ideas? Thanks!
Just figured this out. I was calling overflow: hidden on my .main-nav class, and that was hiding my border-bottom.

CSS transition not working when mouse moved off link

im having some troubles with my CSS, i have a button i made and i have given it some CSS to add a color changing effect with webkit transition, the color change works on hover but when mouse is taken off button it wont show effect of it returning to how it was before, heres my css
.button-blue{
border: 1px solid #00B7EF;
border-radius: 5px;
color: #00B7EF !important;
background-color: transparent;
-webkit-transition-property: background-color, color;
-webkit-transition-duration: 0.5s;
webkit-property: background-color, color;
webkit-duration: 0.5s;
}
.button-blue:hover {
border: 1px solid #00B7EF;
border-radius: 5px;
color: white !important;
background-color: #00B7EF;
-webkit-transition-property: background-color, color;
-webkit-transition-duration: 0.5s;
webkit-property: background-color, color;
webkit-duration: 0.5s;
}
You already have transition properties for your href stated previously so just state it once with your href before and remove the transition properties from your button so your css would look like the following:
Working fiddle Fiddle
.navigation-bar ul li a {
color: #333333;
text-decoration: none;
font-family: 'Roboto', sans-serif;
font-size: 19px;
font-weight: 400;
font-style: bold;
padding: 5px 5px 10px 10px;
-webkit-transition-property: background-color, color;
-webkit-transition-duration: 0.5s;
webkit-property: background-color, color;
webkit-duration: 0.5s;
}
.button-blue{
border: 1px solid #00B7EF;
border-radius: 5px;
color: #00B7EF !important;
background-color: transparent;
}
.button-blue:hover {
border: 1px solid #00B7EF;
border-radius: 5px;
color: white !important;
background-color: #00B7EF;
}
webkit-property and webkit-duration aren't CSS properties.
The correct syntax is transition-property and
transition-duration.
-webkit- is only a vendor prefix for CSS features on Google Chrome
and newer versions of Opera.
In pseudoclasses as :hover state, you only have to declare
properties that you will change, isn't necessary repeat already
declared ones. So, border-radius is out (unless you
want to change it).
You have to set the transition in the default state. If you declare
again on :hover state, you are creating a second instance for the
transition, that's why you got this animation on your button.
You already have declared a transition in .navigation-bar ul li a (And have a transition only for color, not background).
So, now you have a problem with specificity, because targeting a parent class and then directly targeting to an HTML
element in CSS has more priority than targeting only a class
(You can check it here).
If all of your a element in your .navigation-bar will have
the same transition, you can set it here. (Not ideal, but it works
cleaner and will be less changes.)
You also need to add a transition for background. This doesn't alter
the rest of your links, because if you don't set a background in
hover (or focus) state, it will not change.
And obviously, you have to remove the transition from
.button-blue, because you will not use it anymore (It would be
repetitive).
Try to modularise more your CSS (don't repeat yourself). You
can learn more searching for BEM, OOCSS or SMACSS
(It's a matter of taste)

Draw a Border but have it not have it inherit object opacity

Please see the following jsBin:
http://jsbin.com/uyonux/1
It is working as desired on the hover state. However the focus state does not work as desired on focus i would like the blue color to not inherit the opacity of .4 i want it the solid #13A3F7 color. Is there any way to append the border without having it use the element opacity?
I tried pseudo elements but they also inherit opacity.
The other solution could be to take 60% plus of #13A3F7 but i don't think that works due to saturation.
I know i could change the image but the point is we are trying to use one black icon and then adjust it with opacity on the various states.
Thanks
button {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAALElEQVR42mNgwA/+QzHZYGAM2E8ADwED6B+I+ynEpPsLzfJBYgBFYTDEMxMA8SA+M9tIcT0AAAAASUVORK5CYII=") ;
border: none;
height: 23px;
width: 26px;
background-repeat: no-repeat;
opacity: 0.4;
filter: alpha(opacity=40);
background-position: center center;
}
button:focus {
border: 1px solid #13A3F7;
}
button:hover {
background-color: #CFCFCF;
box-shadow: 0 1px #696969;
opacity: 0.65;
filter: alpha(opacity=65);
cursor:pointer;
}
Also I'll need to support IE8 for now :(
You could use RGBa colors.
Like this:
border: 10px solid #ff0000;
border-color: rgba( 255,0,0,0.5);
Use outline: instead of border, like this:
button:focus, button:active {
outline: 1px solid #13A3F7 !important;
}
Edit: You could achieve this by using a link instead of button. Check out this Plunker: http://plnkr.co/edit/NZ3lOyFBSxOFwSExyBpA?p=preview

How do I make a transparent border with CSS so that contents don't shift position? [duplicate]

This question already has answers here:
CSS hover border makes elements adjust slightly
(14 answers)
Closed 25 days ago.
I have an li styled as follows:
li{
display:inline-block;
padding:5px;
border:1px solid none;
}
li:hover{
border:1px solid #FC0;
}
When I hover over the li the border appears, but the li's shift around. Is it possible to have the border appear without causing the element to shift? Almost like having an invisible border, and then on hover make it appear?
You can use "transparent" as a colour. In some versions of IE, that comes up as black, but I've not tested it out since the IE6 days.
http://www.researchkitchen.de/blog/archives/css-bordercolor-transparent.php
Many of you must be landing here to find a solution for opaque border instead of a transparent one. In that case you can use rgba, where a stands for alpha.
.your_class {
height: 100px;
width: 100px;
margin: 100px;
border: 10px solid rgba(255,255,255,.5);
}
Demo
Here, you can change the opacity of the border from 0-1
If you simply want a complete transparent border, the best thing to use is transparent, like border: 1px solid transparent;
You could remove the border and increase the padding:
li {
display: inline-block;
padding: 6px;
border-width: 0px;
}
li:hover {
border: 1px solid #FC0;
padding: 5px;
}
<ul>
<li>Hovering is great</li>
</ul>
hey this is the best solution I ever experienced.. this is CSS3
use following property to your div or anywhere you wanna put border trasparent
e.g.
div_class {
border: 10px solid #999;
background-clip: padding-box; /* Firefox 4+, Opera, for IE9+, Chrome */
}
this will work..
Yep, you can use border: 1px solid transparent
Another solution is to use outline on hover (and set the border to 0) which doesn't affect the document flow:
li{
display:inline-block;
padding:5px;
border:0;
}
li:hover{
outline:1px solid #FC0;
}
NB. You can only set the outline as a sharthand property, not for individual sides. It's only meant to be used for debugging but it works nicely.
Since you said in a comment that the more options you have, the better, here's another one.
In CSS3, there are two different so-called "box models". One adds the border and padding to the width of a block element, while the other does not. You can use the latter by specifying
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
Then, in modern browsers, the element will always have the same width. I.e., if you apply a border to it on hover, the width of the border will not add to the overall width of the element; the border will be added "inside" the element, so to speak. However, if I remember correctly, you must specify the width explicitly for this to work. Which is probably not an option for you in this particular case, but you can keep it in mind for future situations.
This blog entry has a way to emulate border-color: transparent in IE6. The below example includes the "hasLayout" fix that is brought up in the blog entry comments:
/* transparent border */
.testDiv {
width: 200px;
height: 200px;
border: solid 10px transparent;
}
/* IE6 fix */
*html .testDiv {
zoom: 1;
border-color: #FEFEFE;
filter: chroma(color=#FEFEFE);
}
Make sure that the border-color used in the IE6 fix is not used anywhere in the .testDiv element. I changed the example from pink to #FEFEFE because that seems even less likely to be used.
Use transparent property
border-color : transparent;
The easiest solution to this is to use rgba as the color: border-color: rgba(0,0,0,0); That is fully transparent border color.

Resources