I'm developing a site and the navigation buttons have 3 states as usual, the initial idle state, a hover state and a click state and a state to show that's the page your on.
I thought I'd add some nice transitions to the :hover and :active states, and while the :hover works nicely I can't seem to get the :active to work as I want.
If you take a look at this fiddle you'll have a clearer idea of what I'm trying to achieve:
http://jsfiddle.net/number8pie/3BvhM/2/
As you can see on :hover there is an opacity transition that I think looks quite nice, but when you click the link I want about_us.png and about_us_hover.png to be set to opacity 0 (using the transition) and about_us_active.png to be left visible.
Here's the HTML:
<ul class="right"> <!-- no closing tag on <li> so that the whitespace between elements is removed-->
<li id="about-us">
<a class="nav-link" href="#">
<div class="icon-cont">
<img class="top" src="http://s28.postimg.org/7u46xdbjd/about_us.png">
<img class="middle" src="http://s28.postimg.org/mel9s76i1/about_us_hover.png">
<img class="bottom" src="http://s28.postimg.org/bt1eg706h/about_us_active.png">
</div>
<span class="nav-text">about us</span>
</a>
<li id="products">
<a class="nav-link" href="#"><span class="nav-text">products</span></a>
<li id="the-team">
<a class="nav-link" href="#"><span class="nav-text">the team</span></a>
<li id="environment">
<a class="nav-link" href="#"><span class="nav-text">environment</span></a>
<li id="contact">
<a class="nav-link" href="#"><span class="nav-text">contact</span></a>
</ul>
And the CSS:
ul li {
height: 56px;
width: 56px;
margin: 0;
font-family: 'RobotoLight';
font-size: 21px;
display: inline-block;
text-transform: uppercase;
}
.icon-cont {
position: relative;
height: 56px;
width: 56px;
margin: 0;
}
.icon-cont img {
position: absolute;
left: 0;
-webkit-transition: opacity 0.4s ease-in-out;
-moz-transition: opacity 0.4s ease-in-out;
-o-transition: opacity 0.4s ease-in-out;
transition: opacity 0.4s ease-in-out;
}
.icon-cont img.top {
z-index: 30;
}
.icon-cont img.middle {
z-index: 20;
}
.icon-cont img.bottom {
z-index: 10;
}
.icon-cont img.top:hover {
opacity: 0;
}
.icon-cont img.top:active {
opacity: 0;
}
.icon-cont img.middle:active {
opacity: 0;
}
.nav-text {
font-size: 0;
position: absolute;
left: -1000px;
}
Thanks in advance for any hep and or suggestions.
You can do most of this using some CSS trickery- namely by relying on the :checked state of a sibling hidden input to control the appearance of a label.
To set the state depending on the current page, you'll likely need to use some JS to identify the page, then apply a suitable class to the element in question.
This will work for on/off click states. If you want a depress (mousedown) state, you should likely use a button element instead of anchor a tags in your code to apply :active to.
Demo Fiddle
(alternate demo using a button and :active)
HTML
<input type='checkbox' id='menuItem' />
<label for='menuItem'>i</label>
CSS
input {
display:none;
}
label {
display:inline-block;
height:50px;
width:50px;
line-height:50px;
color:white;
font-size:1.5em;
font-style:italic;
font-family:arial;
background:lightgreen;
text-align:center;
position:relative;
transition:all 200ms ease-in;
}
label:after {
height:30px;
width:30px;
content:'';
border:4px solid white;
border-radius:100%;
display:inline-block;
position:absolute;
left:6px;
top:6px;
opacity:0;
transition:all 200ms ease-in;
}
label:hover:after {
opacity:1;
}
input:checked+label {
background:none;
color:lightgreen;
}
input:checked+label:after {
border-color:lightgreen;
}
Here it is using javascript. I add a class to the link onmousedown and use that to add the active styles. I've used plain js as I'm not sure if you're using jQuery or some other DOM manipulation library. The code is here:
http://jsfiddle.net/John_C/xsdnL/3/
var navLinks = document.getElementsByClassName('nav-link');
Array.prototype.forEach.call(navLinks, function(link) {
link.addEventListener("mousedown", function(){
this.className += " active";
}, false);
link.addEventListener("mouseup", function(){
this.className = "nav-link";
}, false);
});
Related
So, on hoovering an image, a button appears onto the image, but it is not clickable . The same applies for links or anything inside the div holding the image. I was wondering how i can get over with this.
My html
<div class="content_img">
<img [src]="mydata.image.original" >
<div >
<button type="button"class="btn btn-primary"> Description </button>
</div>
</div>
My Css
/* Parent Container */
.content_img{
position: relative;
width: 90%;
}
/* Child Text Container */
.content_img div{
position: absolute;
bottom: 0;
right: 0;
background:black;
color: white;
margin-bottom: 5px;
font-family: sans-serif;
opacity: 0.7;
visibility: hidden;
-webkit-transition: visibility 0s, opacity 0.5s linear;
transition: visibility 0s, opacity 0.5s linear;
}
/* Hover on Parent Container */
.content_img:hover{
cursor: pointer;
}
.content_img:hover div{
width: 100%;
height: 100%;
visibility: visible;
opacity: 0.75;
}
Can anyone help me out please
What do you mean by that ? I tested the code and <a> tag works. I tested it like follow :
<a href="www.google.com" target="">
<button type="button"class="btn btn-primary">Description</button>
</a>
The button link is clickable. If it is a button, did you set a onclick event so that button call your function?
I need an element to appear where another was, let's say on hover for the sake of an example. And I need to use CSS animations to make its transition smoother. So I can't use display property. And instead, I have to use this, right?
div {
visibility: hidden;
opacity: 0;
}
But my elements need to overlap, as in where one was, the other has to show instead. With display, that was pretty easy, but with this, I have no clue how to do this without making it too messy.
Can someone help me out? Here's the basic outline of my code:
.first-outline .first:hover {
visibility: hidden;
opacity: 0;
}
.first-outline .second {
visibility: hidden;
opacity: 0;
}
.first-outline:hover second {
visibility: initial;
opacity: 1;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<li class="list-group-item first-outline">
<p class="first">First</p>
<p class="second">Second</p>
</li>
<!-- Or something like this, but it still doesn't work -->
<li class="list-group-item second-outline">
<span class="first">First</span>
<span class="second">Second</span>
</li>
Thank you.
Give the container a positon: relative and the inner divs positin: absolute then play with the hover states and opacity.
add transition property for smooth effect
.first-outline {
position:relative;
}
.first-outline .first, .first-outline .second {
position: absolute;
top: 0 ;
left: 0;
width: 100%;
height: 100%;
transition: opacity 500ms linear;
-webkit-transition: opacity 500ms linear;
-moz-transition: opacity 500ms linear;
}
.first-outline:hover .first, .first-outline .second {
opacity: 0;
}
.first-outline:hover .second {
opacity: 1;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<li class="list-group-item first-outline">
<p class="first">First</p>
<p class="second">Second</p>
</li>
Does anyone know why my .cd-img-overlay class is not working when I hover over a list item?
My live code here
CSS:
#cd-team .cd-img-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(92, 75, 81, 0.9);
opacity: 0;
border-radius: .25em .25em 0 0;
-webkit-transition: opacity 0.3s;
-moz-transition: opacity 0.3s;
transition: opacity 0.3s;
}
HTML:
<li>
<a href="#0" data-type="member-1">
<figure>
<img src="images/bruce.jpg" alt="Team member 1" />
<div class="cd-img-overlay"><span>View Bio</span></div>
</figure>
<div class="cd-member-info">
John Smith <span>Founder & President</span>
</div>
</a>
</li>
I can't seem to get that overlay class to work like shown in this tutorial's demo when you hover over a team member: https://codyhouse.co/demo/side-team-member-bio/index.html
Hi change the opacity for the overlay to 1 and you're there. :) It's currently set to opacity: 0 for your hover class.
Do you have a hover state to change the opacity to 1? For example:
a:hover .cd-img-overlay { opacity: 1; }
add this to your code an it will work .. its just because on hover you are not changing the opacity to 1.
#cd-team li:hover .cd-img-overlay {
opacity: 1;
}
You are not changing the opacity to 1 when hovering. That's why the problem is. Use the following code that is present in the working url.
.no-touch #cd-team li:hover .cd-img-overlay { opacity: 1; }
I have the following codepen, this is a basic positioned label with the number and marker text:
<span href="#" class="part-marker">
1<span> marker text</span>
</span>
How can I get it to slide out on hover using css3 transitions? I've tried using this with no success??
See below a simplified version- the crux here being that you cant make a transition on properties that don't scale, so where you have the element going from display:none t inline-block it simply goes from hidden to shown as there are no intermediary points. What you can do instead is use a combination of max-width and overflow as outlined below.
Demo Fiddle
HTML
<div> <a href='#'>1</a>
<span>Label</span>
</div>
CSS
a {
display:inline-block;
background:blue;
color:white;
padding:0 5px;
}
div {
position:relative;
}
div span {
position:absolute;
display:inline-block;
max-width:0;
overflow:hidden;
transition:all 1s ease-in;
}
a:hover+span {
max-width:100%;
}
Take a look at this code:
HTML
<a href="#" class="marker-label" text="marker text">
1
</a>
CSS
.marker-label {
display:block;
background:blue;
color:white;
padding:4px 8px;
font-size:1em;
line-height:1;
position:relative;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
width:10px;
}
.marker-label:hover {
width:80px;
}
.marker-label:after {
content:attr(text);
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
position:absolute;
left:-100px;
}
.marker-label:hover:after {
left:20px;
}
And here is a FIDDLE
You can use a negative text-indent too : http://codepen.io/anon/pen/xalDc/
span {
text-indent:-150px;
overflow:hidden;
display:inline-block;/* triggers layout */
transition: all 1s ease-in-out;
/* position:absolute ; not needed since a is already so */
}
&:hover {
span {
text-indent:0;
}
}
i am having a problem with the on :hover the tooltip is supposed to visible, but it does not happening .I am using only CSS no js included.Need help.
Thank you in advance...:)
here is my css :
.tooltip{
position: relative;
opacity: 0;
padding: 10px;
background: #9B59B6;
border-radius: 5px;
-webkit-transition:all 0.2s ease-in;
-moz-transition:all 0.2s ease-in;
transition:all 0.2s ease-in;
}
HTML :
<div class="wrapper">
<span class="tooltip">Hello ! This is tooltip....</span>
Hover Me !
</div>
You need some code to actually trigger the animation.
In my example below, I have nested the <span> inside the <a> in order to use :hover.
<div class="wrapper">
<a href="#" class="show">
Hover Me !
<span class="tooltip">Hello ! This is tooltip....</span>
</a>
</div>
a:hover span {
opacity:1;
}
http://jsfiddle.net/6RV5n/
EDIT:
Here's the same concept but using a CSS adjacent sibling selector so as not to nest the elements:
<div class="wrapper">
Hover Me !
<span class="tooltip">Hello ! This is tooltip....</span>
</div>
a.show:hover + span.tooltip {
opacity:1;
}
http://jsfiddle.net/7pT8Y/3/
Keep in mind that CSS sibling selectors may not work in older version of IE.
If you need to display the tooltip while the user hovering on the div wrapper..
Use the following CSS.
.wrapper:hover > .tooltip{
opacity: 1;
}
Check this... http://jsfiddle.net/TsQB5/
[EDITED]
.tooltip{
display:none;
}
.show:hover > .tooltip{
display: block;
}
This can solve the problem..