I have a button that on hover will go up by 10px. The problem is if the cursor is positioned at just barely under the button when the button is transitioned or transitioning by 10px, it twitches.
.talk-to-us {
padding: 10px;
height: 43px;
width: 148px;
background-color: #00cdac;
position: relative;
transition: top ease .40s;
top: 0;
}
.talk-to-us:hover {
top: -10px;
}
.link {
color: white;
font-size: 14px;
padding: 10px;
}
<button class="talk-to-us">
<a class="link" href="#">TALK TO US!</a>
</button>
How do I prevent this behavior solely by CSS?
One possibility would be to add a pseudo element that extends downward far enough to account for the upward shift, so the mouse remains within the target area. With a transparent background you won't see it but it still captures mouse events.
The only change here is the addition of the ::after selector/rules:
.talk-to-us {
padding: 10px;
height: 43px;
width: 148px;
background-color: #00cdac;
position: relative;
transition: top ease .40s;
top: 0;
}
.talk-to-us:hover {
top: -10px;
}
.talk-to-us:hover::after {
content: '';
position: absolute;
height: 20px;
background: transparent;
left: 0;
right: 0;
top: 100%;
}
.link {
color: white;
font-size: 14px;
padding: 10px;
}
<button class="talk-to-us">
<a class="link" href="#">TALK TO US!</a>
</button>
Related
I have a :after pseudo element that is placed below each of my nav bar buttons with one CSS selector, but for some reason it looks like the heights of the element underneath when you hover over the buttons "home" and "projects" are different from "about me" and "skills". Any idea as to why?
Here is a link to some code replicating the issue so you can see the different heights in question.
.nav-button {
font-weight: bold;
font-size: 24px;
margin-bottom: 36px;
width: 100%;
}
.nav-bar {
list-style-type: none;
padding-left: 5px;
}
.nav-button:after {
background: none repeat scroll 0 0 transparent;
bottom: 0;
content: "";
display: block;
height: 2px;
left: 0;
position: relative;
background: #E7AB79;
transition: width 0.3s ease 0s, right 0.3s ease 0s;
width: 0;
}
#home-button:hover:after {
width: 68px;
right: 0;
}
#aboutme-button:hover:after {
width: 110px;
left: 0;
}
#projects-button:hover:after {
width: 90px;
left: 0;
}
#skills-button:hover:after {
width: 64px;
left: 0;
}
.nav-button:hover {
cursor: pointer;
}
<nav>
<ul class="nav-bar">
<li class="nav-button button" id="home-button">Home</li>
<li class="nav-button button" id="aboutme-button">About Me</li>
<li class="nav-button button" id="projects-button">Projects</li>
<li class="nav-button button" id="skills-button">Skills</li>
</ul>
</nav>
I am having the weirdest problem: I am working on a portfolio page with images that should link to the various projects. There are 6 of these in total. Each of the images has a button that should live on top of it. When the button is hovered on by the user, it changes color, the cursor changes, and a popup with a short description of the project opens. When the button is clicked, there is an event listener that redirects to the project's page.
The problem is that in 2 out of the 6 instances, the moment I position the buttons inside the image, the buttons lose all functionality (including the event listener). As far as I can tell the code governing these 2 instances is the same as the other 4 where there is no such problem.
code where it doesn't work:
HTML:
<div class="container" id="linkTwo">
<img src="assets/images/bonez2.jpg" alt="bonez" style="width:200px; height:200px;" class="linkpic" >
<div class="btn1"id="btn1">Bone's Beatz<span id="bonezPop"> */some text that pops up/* </span></div>
</div>
CSS:
#linkTwo {
position: absolute;
top: 100px;
left: 230px;
}
#linkTwo #btn1:hover {
background-color: black;
}
#btn1 {
position: absolute;
left:20px;
padding-left: 23px;
padding-right: 23px;
}
#btn1 #bonezPop {
visibility: hidden;
width: 250px;
background-color: #883043;
color: #aa9e9e;
text-align: center;
border-radius: 6px;
border-style: solid;
border-color: black;
border-width: 2px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
#btn1:hover #bonezPop {
visibility: visible;
}
.container #btn1 {
position: absolute;
top: -2px;
left: 20px;
font-size: 16px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 53px;
padding-right: 53px;
border: none;
cursor: pointer;
border-radius: 5px;
}
code that DOES work:
HTML:
<div class="container" id="linkFive">
<img src="assets/images/weather.jpg" alt="weather app" style="width:200px;height:200px;" class="linkpic">
<div class="btn3" id="btn3">Weather App<span id="weatherPop"> */some text that pops up */</span></div>
</div>
CSS:
#linkFive {
position: absolute;
top:320px;
}
#btn3 #weatherPop {
visibility: hidden;
width: 250px;
background-color: #883043;
color: #aa9e9e;
text-align: center;
border-radius: 6px;
border-style: solid;
border-color: black;
border-width: 2px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
#btn3:hover #weatherPop {
visibility: visible;
}
#btn3 {
padding-left: 53px;
padding-right: 53px;
}
.container .btn3 {
position: absolute;
top: -2px;
left: 20px;
font-size: 16px;
padding-top: 10px;
padding-bottom: 10px;
padding-left: 60px;
padding-right: 40px;
border: none;
cursor: pointer;
border-radius: 5px;
}
.container .btn3:hover {
background-color: black;
}
I realize this whole thing would have been done much more easily with WordPress or some such, but this is a class assignment that requires I do this with code.
Thanks!
Short gif of how the problem looks
Found the answer. It was a different CSS rule that was for some reason breaking it:
.container {
position: relative;
width: 50%;
}
commenting this out solved the problem.
I have a notification icon (font-awesome) which shows the number of notifications.
I am having a problem trying to get the number to display in the correct position, as shown in see below image
I need the text to be smaller and move right and up a little...
here is the code
.header .bubble {
border-radius: 100%;
height: 14px;
width: 14px;
background-color: rgba(226, 32, 91, 0.77);
color: #ffffff;
text-align: top;
position: relative;
top: 0px;
float: right;
right: -3px;
}
<a href="javascript:;" id="notification-center" class="icon-set globe-fill" data-toggle="dropdown"><span class="bubble">2</span>
Can anyone help, I am new to this.
example1: using background image
The best way to do this is to use position:absolute to child span of parent anchor.
a.notif {
position: relative;
display: block;
height: 50px;
width: 50px;
background: url('http://i.imgur.com/evpC48G.png');
background-size: contain;
text-decoration: none;
}
.num {
position: absolute;
right: 11px;
top: 6px;
color: #fff;
}
<span class="num">2</span>
example2: using font awesome icon
If you want to use font-awesome icon
this is code for it
a.fa-globe {
position: relative;
font-size: 2em;
color: grey;
cursor: pointer;
}
span.fa-comment {
position: absolute;
font-size: 0.6em;
top: -4px;
color: red;
right: -4px;
}
span.num {
position: absolute;
font-size: 0.3em;
top: 1px;
color: #fff;
right: 2px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<a class="fa fa-globe">
<span class="fa fa-comment"></span>
<span class="num">2</span>
</a>
Hallo I am trying to create a button aligned to the right of the screen which leads to the next article.
Everything works as I want it, till the point when I add the css transition.
As you can see in the fiddle I have twice the exact same code, except that the blue bar does have a css transition property and the green bar does not have a transition.
I am using the 64bit version of chrome (45.0.2453.0 dev-m) and while in here the green bar works as supposed when hovered, the content from the blue bar with the transition does have some major alignment bug. It seems that the content of the containers pops out of the containers.
<nav class="nav-next">
<a href="link" class="link">
<div class="thumbnail">
<img width="100" height="100" src="http://travelwithoutplan.com/wp-content/uploads/DSC01985_Vibrance-100-200x200.jpg" class="attachment-100x100 wp-post-image" alt="DSC01985 Vibrance 100" />
</div>
<div class="headline">Travel Information for Liechtenstein</div>
</a>
</nav>
CSS (without transition it works - but with transition it causes an alignment bug)
/*
.nav-next {
-moz-transition: width .5s;
-o-transition: width .5s;
-webkit-transition: width .5s;
transition: width .5s;
}
*/
.nav-next {
background-color: lightblue;
overflow: hidden;
position: fixed;
top: 50px;
left: auto;
right: 0;
box-sizing: border-box;
width: 30px;
height: 120px;
}
.nav-next:hover {
width: 330px;
}
.nav-next .headline:after, .nav-next .link {
display: block;
border-top: 1px solid #8c8c8c;
}
.nav-next .link {
background: #fff;
height: 120px;
width: 300px;
box-sizing: border-box;
padding: 10px;
position: absolute;
right: 0;
top: 0;
margin-left: 30px;
margin-right: 30px;
border: 1px solid #8c8c8c;
border-right: none;
}
.nav-next:hover .link {
margin-left: 0;
}
.nav-next .link:before {
color: #262626;
left: auto;
right: -23px;
position: absolute;
top: 52px;
font-size: 16px;
font-size: 1rem;
content: "\e12e";
font-family: wp-svg-plugin-icon-set1!important;
}
.nav-next .thumbnail {
position: relative;
width: 100px;
float: left;
margin-left: 0;
margin-right: 5px;
}
.nav-next .headline {
color: #595959;
height: 100px;
overflow: hidden;
padding-right: 10px;
padding-top: 5px;
position: relative;
left: 4px;
right: 0;
font-size: 14px;
}
.nav-next .headline:after {
content: "Next Article";
position: absolute;
width: 100%;
bottom: 0;
padding-top: 5px;
text-align: right;
}
http://jsfiddle.net/64g0vzq1/4/
Here you can see how with Chrome 64bit-version (45.0.2453.0 dev-m) the aligment of the content from the hovered blue bar (with css transition) is wrong. The text disappears behind the image, the image positionig is wrong etc.
Below the content of the green bar (without css transition) is shown correctly.
Is this a css error or something? How can I fix it?
Many thanks in advance!
I have a button with hover effect.
When I am applying the hover class then the image(down arrow) is missing. If I remove hover class then I can see the image.
Html code with hover class
<button type="submit" class="button uppercase btn-1b">home</button>
Html code without hover class
<button type="submit" class="button uppercase">home</button>
Demo - With Image but without hover effect
Demo -- With hover effect but missing the image.
Any help is highly appreciated. Thanks in advance.
You can define arrow image in .button::before pseudo-element and transitioning background in .btn-1b:after:
.button::before {
background-image: url("http://s12.postimg.org/63ise2fkp/button_arrow.png?noCache=1431762044");
background-repeat: no-repeat;
content: "";
height: 5px;
position: absolute;
right: 4.1rem;
top: 1.1rem;
width: 8px;
}
.uppercase {
text-transform: uppercase;
}
.button {
color: white;
position: relative;
z-index: 1;
background: #000;
border: 1px solid #9d9368;
font-size: 17px;
padding: 0.5rem 2rem;
width: 220px;
display: inline-block;
cursor:pointer;
}
.btn-1b:after {
content: '';
position: absolute;
transition: all 0.3s ease 0s;
width: 100%;
height: 0;
top: 0;
left: 0;
background: #ffffff;
z-index: -1;
}
.btn-1b:hover, .btn-1b:active {
color: #0e83cd;
}
.btn-1b:hover:after, .btn-1b:active:after {
height: 100%;
}
<button type="submit" class="button uppercase btn-1b">home</button>