How can i remove from element the hover effect when clicked? - css

I have this code
http://jsfiddle.net/F6Jqm/1/
I want when user clicks the png the hover <span> to stay. And when he clicks it again to return to the original form.

You could do this by adding a "stay" class on click
like in this fiddle: http://jsfiddle.net/F6Jqm/3/
The difference is in css:
#navigationMenu a:hover span, #navigationMenu a.stay span{
width:auto; padding:0 20px;overflow:visible;
}
And Added some jquery:
$(document).ready(function(){
$("a").click(function(){
$(this).toggleClass("stay");
});
});

I've update the fiddle
Try this:
var count = 0;
document.getElementsByClassName('home')[0].onclick = function() {
count = 1 - count;
if (count) {
document.getElementById('navigationMenu').className = 'stayHover';
}
else {
document.getElementById('navigationMenu').className = 'menuHover';
}
}
You could use toggleClass instead if you don't mind importing jQuery for this.

Here's a solution with only CSS (no Javascript). I only tested on firefox and chrome, but it should go on all recent browsers.
http://jsfiddle.net/F6Jqm/6/
The idea is to use the pseudoselector :checked of an input type checked and the relative label and setting it on the icon with opacity: 0.
CSS:
#navigationMenu li{
list-style:none;
height:20px;
width:20px;
}
#navigationMenu input[type=checkbox] {
position:absolute;
z-index: 1;
opacity:0;
}
#navigationMenu span{
width:0;
left:22px;
padding:0;
position:absolute;
overflow:hidden;
font-family:'Myriad Pro',Arial, Helvetica, sans-serif;
font-size:18px;
font-weight:bold;
letter-spacing:0.6px;
white-space:nowrap;
line-height:20px;
-webkit-transition: 0.25s;
-moz-transition: 0.25s;
transition: 0.25s;
}
#navigationMenu label {
background:url('http://www.tigercamera.com/front/img/home.png') transparent no-repeat;
padding:0px;
height:20px;
width:20px;
display:block;
position:relative;
border: 0px;
}
/* General hover styles */
#navigationMenu input:hover + label span{ width:auto; padding:0 20px;overflow:visible; }
#navigationMenu input:checked + label span{ width:auto; padding:0 20px;overflow:visible; }
/* Green Button */
#navigationMenu .home { background-position:0 0;}
#navigationMenu .home span{
background-color:#7da315;
color:#3d4f0c;
text-shadow:1px 1px 0 #99bf31;
}
HTML:
<div id="main">
<ol id="navigationMenu">
<li>
<input name="check" type="checkbox"/>
<label for="check" class="home">
<span>Home</span>
</label>
</li>
</ol>
</div>

There you go(with pure js): http://jsfiddle.net/F6Jqm/7/
var nav = document.getElementById('navigationMenu'),
items = nav.getElementsByTagName('a'),
i;
for( i=0; i<items.length; i++){
items[i].onclick = function(){
if( this.classList.contains('active') ){ this.classList.remove('active') }else{
this.className = this.className + ' active';
}
};
}

Related

How to move label of input text field above when user clicks on input field - angularjs

I have a input type="text" field. By intially the field should contain field name. When user clicks on that input field the field name should move up and leave space to enter the value.
I searched in google but I couldn't found any solution related to my need.
It will be great if anyone could help me.
Initally form looks like
After clicking on field
The thing you want can be achieved by implementing material design. Use this: https://codepen.io/sevilayha/pen/IdGKH
* { box-sizing:border-box; }
/* basic stylings ------------------------------------------ */
body { background:url(http://scotch.io/wp-content/uploads/2014/07/61.jpg); }
.container {
font-family:'Roboto';
width:600px;
margin:30px auto 0;
display:block;
background:#FFF;
padding:10px 50px 50px;
}
h2 {
text-align:center;
margin-bottom:50px;
}
h2 small {
font-weight:normal;
color:#888;
display:block;
}
.footer { text-align:center; }
.footer a { color:#53B2C8; }
/* form starting stylings ------------------------------- */
.group {
position:relative;
margin-bottom:45px;
}
input {
font-size:18px;
padding:10px 10px 10px 5px;
display:block;
width:300px;
border:none;
border-bottom:1px solid #757575;
}
input:focus { outline:none; }
/* LABEL ======================================= */
label {
color:#999;
font-size:18px;
font-weight:normal;
position:absolute;
pointer-events:none;
left:5px;
top:10px;
transition:0.2s ease all;
-moz-transition:0.2s ease all;
-webkit-transition:0.2s ease all;
}
/* active state */
input:focus ~ label, input:valid ~ label {
top:-20px;
font-size:14px;
color:#5264AE;
}
/* BOTTOM BARS ================================= */
.bar { position:relative; display:block; width:300px; }
.bar:before, .bar:after {
content:'';
height:2px;
width:0;
bottom:1px;
position:absolute;
background:#5264AE;
transition:0.2s ease all;
-moz-transition:0.2s ease all;
-webkit-transition:0.2s ease all;
}
.bar:before {
left:50%;
}
.bar:after {
right:50%;
}
/* active state */
input:focus ~ .bar:before, input:focus ~ .bar:after {
width:50%;
}
/* HIGHLIGHTER ================================== */
.highlight {
position:absolute;
height:60%;
width:100px;
top:25%;
left:0;
pointer-events:none;
opacity:0.5;
}
/* active state */
input:focus ~ .highlight {
-webkit-animation:inputHighlighter 0.3s ease;
-moz-animation:inputHighlighter 0.3s ease;
animation:inputHighlighter 0.3s ease;
}
/* ANIMATIONS ================ */
#-webkit-keyframes inputHighlighter {
from { background:#5264AE; }
to { width:0; background:transparent; }
}
#-moz-keyframes inputHighlighter {
from { background:#5264AE; }
to { width:0; background:transparent; }
}
#keyframes inputHighlighter {
from { background:#5264AE; }
to { width:0; background:transparent; }
}
<div class="container">
<h2>Google Material Design in CSS3<small>Inputs</small></h2>
<form>
<div class="group">
<input type="text" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Name</label>
</div>
<div class="group">
<input type="text" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Email</label>
</div>
</form>
<p class="footer">
a tutorial by scotch.io
</p>
</div>
Use material design and you can use md-input-container
<md-input-container class="md-block">
<label>Username</label>
<input type="text">
</md-input-container>
Material design input

Show div and hide another on hover with transition

I have searched other questions but none are giving the result I am looking for.
I am trying to :hover in order to show another div and also hide another div at the same time. I can't wrap all divs in one parent div, because then the div I want to hide being :hover over will trigger the show/hide... and in addition do it with a nice transition.
Only when hovering over the 'hover me' text should the show/hide trigger.
The .remove_me class and text 'make me disappear' isn't disappearing on :hover. That is what I am unable to achieve.
Fiddle
CSS
.hover_me {
cursor:pointer;
-webkit-transition: .4s;
transition: .4s;
display:block;
height:30px;
background:#ccc;
width:70px;
line-height:30px;
text-align:center;
}
.show_me {
display:none;
}
.hover_me:hover + .remove_me {
display:none;
}
.hover_me:hover + .show_me {
display:block;
}
.remove_me {
display:block;
HTML
<div class="hover_me">hover me</div>
<div class="show_me">show me</div>
<div class="remove_me">make me disappear</div>
This for example is not what I want to happen: http://jsfiddle.net/MBLZx/ the show/hide should only be triggered by the 'hover me' text
It should work as you want it to if you do it like this:
I changed your CSS code
.hover_me:hover + .remove_me {
display:none;
}
To:
//Note the tilde
.hover_me:hover ~ .remove_me {
display:none;
}
Explanation on the tilde
Hope this helps
I have changed your selector, and changed the display (that can not be animated) to opacity (that can)
.hover_me {
cursor:pointer;
-webkit-transition: .4s;
transition: .4s;
display:block;
height:30px;
background:red;
width:70px;
line-height:30px;
text-align:center;
}
.show_me {
opacity: 0;
}
.hover_me:hover ~ .remove_me {
opacity: 0;
}
.hover_me:hover + .show_me {
opacity: 1;
}
.remove_me {
margin-top: -1em;
opacity: 1;
}
div {
transition: opacity 1s;
}
<div class="hover_me">hover me</div>
<div class="show_me">show me</div>
<div class="remove_me">make me disappear</div>
Actually to select the remove_me you have to apply the one more + as show_me lies in between. + select the next tag class. so we have to put the + .show_me on between
.hover_me:hover + .show_me + .remove_me {
display:none;
}
check the fiddle http://jsfiddle.net/stdeepak22/enmxx59b/
You need to ...
use the general adjacent selector ~ and not the direct adjacent selector + to make .remove_me "disappear"
use opacity or any other property that you can use with transition (not display) to create a show/hide effect
Change your CSS as follows:
.hover_me:hover ~ .remove_me{
display:none;
}
Demo fiddle here
.hover_me {
cursor:pointer;
-webkit-transition: .4s;
transition: .4s;
display:block;
height:30px;
background:red;
width:70px;
line-height:30px;
text-align:center;
}
.show_me {
opacity: 0;
}
.hover_me:hover ~ .remove_me {
opacity: 0;
}
.hover_me:hover ~ .show_me {
opacity: 1;
}
.remove_me {
opacity: 1;
}
.toggled{
position: absolute;
transition: opacity 300ms;
}
<div class="hover_me">hover me</div>
<div class="toggled show_me">show me</div>
<div class="toggled remove_me">make me disappear</div>

Issues with default CSS taking over my code

I've been working on my donation website and I've come to find an issue where the default Buycraft css is taking over the css that I'm writing. I'm extremely new to css and I don't plan on doing it much in the future but for now I need help.
When I inspect element my navbar it gives me a few variables for .navbar .nav > li > a such as a color and a text shadow. I've tried to re-write the code for the text and it's to no avail. I copied it exactly like what inspect element has and I gave the variables !important but nothing changes. If anyone can tell me whats wrong with the navbar button text please help me out.
My website.
Code:
#import "http://fonts.googleapis.com/css?family=Oswald:400,300";
body {
background:url(http://i.imgur.com/tYtIxao.jpg?1);
background-size:cover;
background-repeat:no-repeat;
background-attachment:fixed;
padding:0;
margin:0;
height:100%
}
.navbar {
background:#11CFD9;
position:fixed;
font-family:"Oswald";
top:0;
left:-5px;
right:-5px;
background-color:#11CFD9;
color:#000!important;
box-shadow:0 2px 2px 0 rgba(50,50,50,0.24);
text-align:center;
height:80px;
display:block;
padding-left:5%;
padding-right:20%;
z-index:10
}
.navbar-inner {
background:#11CFD9;
position:fixed;
font-family:"Oswald";
top:0;
left:-5px;
right:-5px;
background-color:#11CFD9;
font-size:x-large;
text-align:center;
display:block;
padding-top:30px;
padding-bottom:30px;
padding-left:5%;
padding-right:20%;
z-index:10
}
.navbar .nav>li>a {
float:none;
padding:10px 15px;
color:#000!important;
text-decoration:none;
text-shadow:0 0 0 #fff!important
}
.nav > li > a {
display:block;
color:#000!important
}
a {
color:#08c;
text-decoration:none
}
.navbar .nav > .active > a,.navbar .nav > .active > a:hover {
color:#fff;
height:auto;
text-decoration:none;
background-color:#11CFD9;
-webkit-box-shadow:inset 0 0 0;
-moz-box-shadow:inset 0 0 0;
box-shadow:inset 0 0 0
}
ul.nav a:hover {
color:#fff!important;
background:#1CDBE6
}
.box-container .basket-dropdown {
padding:20px;
margin-left:-145px;
margin-top:2px
}
.basket-dropdown .checkout {
float:right
}
.checkout {
z-index:9999;
font-family:Oswald;
font-weight:300
}
.row {
margin-left:20px;
margin-right:20px
}
.box-container .checkout {
width:98%!important;
float:none!important
}
.span11 {
width:98%;
float:none!important
}
.box {
background:url();
border:0!important;
margin-top:130px;
position:relative;
padding-right:25px;
padding-left:25px;
width:100%
}
.box-container {
font-family:Oswald;
font-weight:300;
margin-right:5px;
margin-left:5px
}
.box-container .checkout {
width:90%;
position:relative;
float:left;
z-index:0;
top:0
}
.box-container .header {
background-image:url(http://i.imgur.com/PzVJZ4V.png);
background-color:#fff;
border-top-left-radius:1px;
border-top-right-radius:1px;
-webkit-border-radius-topright:5px;
-webkit-border-radius-topleft:5px;
-border-radius-topright:5px;
-border-radius-topleft:5px;
height:33px;
text-align:left;
text-transform:uppercase;
font-size:25px;
padding-top:20px;
font-family:Oswald;
font-weight:300;
border-radius:5px 5px 0 0
}
.box-container .content {
opacity:.9!important
}
.span7 {
width:60%;
margin-left:20px;
border-radius:10px
}
.span4 {
width:25%;
height:15%
}
.clear-fix {
z-index:9999;
top:0;
opacity:.9
}
.logo {
background:url();
background-repeat:no-repeat;
float:none;
z-index:9999;
position:fixed;
left:25%;
height:0!important;
width:0!important
}
.logo span {
opacity:0;
color:#fff;
font-size:0
}
em {
color:red;
font-weight:700;
font-style:normal
}
/*Spinny Heads*/
.image {
display:block;
text-decoration:none;
-webkit-transition:.5s all ease-in-out;
-moz-transition:.5s all ease-in-out;
-o-transition:.5s all ease-in-out;
transition:.5s all ease-in-out
}
.image:hover {
-webkit-transform:rotate(720deg) scale(1.5);
-ms-transform:rotate(720deg) scale(1.5);
-moz-transform:rotate(720deg) scale(1.5);
-o-transform:rotate(720deg) scale(1.5);
transform:rotate(720deg) scale(1.5)
}
.footer {
height:60px;
border-top:1px solid #000;
background:orange;
bottom:0;
margin-right:0;
margin-bottom:0;
width:100%;
z-index:99999;
position:static;
font-family:"Oswald";
left:-5px;
right:-5px;
background-color:#11CFD9;
color:#000!important;
box-shadow:0 2px 2px 0 rgba(50,50,50,0.24);
text-align:center;
display:block
}
The browser decides which css selector is applied over the others depending on its weight. Usually you will find the term CSS specificity describing this.
In your case the .nav > li > a is interpreted to have a very low weight and is therefore overridden by your default stylesheet.
If you remove the > symbols in those selectors it should still be the same result - since there are no nested a elements in the navigation bar you want to exclude, right?
The selector .nav li a has a bigger weight and should therefore take precedence. If that still does not help, please include the css-selector from your Buycraft css file, which is overriding your selector. So we can look at the specific weight of both in comparison.
Have a look at this answer here for another example.
A little background: the css specificity exists in order to make things like the following possible: Imagine, the links on your website should always be displayed in blue. But in your navigation, they should be black.
a { color: blue; }
.navbar a { color: black; }
Since the second selector is more specific, it takes precedence over the general links-are-blue selector and your navigational links are black.

CSS for hover to change same-level element

I am making a little photo gallery and I want there to be an effect on the image when you hover either the image or the text link. You can see an example here:
http://codepen.io/anon/pen/qarvc
Right now, if you hover over any of the entire parent div it triggers the hover effect I want for the image and image span. The problem though, is that if you hover over the empty space to the right of the h4 a, it still triggers the hover but the user can't actually click a link.
Now in the actual work, I have another element floated to the right of the h4 a, so it is not a solution to just make the h4 a a block.
How can I use css to target .gallery-image when h4 a is hovered?
html
<div class="galleries">
<div class="gallery">
<div class="gallery-image">
<span class=""></span>
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTEH-vPVcz7F8Yb18iLtDEjnZsbWfYG4lCFdyhKMRYax1krBnRD" alt="" />
</div>
<h4>gallery name</h4>
</div><!-- end div.gallery -->
css
#content-full {
width:960px;
padding:30px 0 0;
}
.clearboth {
clear:both;
height:0;
}
.gallery {
position:relative;
float:left;
width:300px;
margin:0 10px 35px;
}
.gallery-image span {
background:url("http://inventionhome.com/wp-content/uploads/2014/07/zoom.png") no-repeat center center;
width:90px;
height:90px;
display:none;
z-index:999;
margin:auto;
position:absolute;
top:-50px; left:0; bottom:0; right:0;
}
.gallery-image {
background-color:#4576a4;
}
.gallery-image:hover span, .gallery:hover .gallery-image span {
display:block;
}
.gallery-image img {
display:block;
width:100%;
height:230px;
-webkit-transition: all 200ms ease-out;
-moz-transition: all 200ms ease-out;
-o-transition: all 200ms ease-out;
transition: all 200ms ease-out;
}
.gallery-image:hover img, .gallery:hover .gallery-image img {
opacity:0.2;
}
.galleries h4 {
margin-top:5px;
line-height:27px;
}
.galleries h4 a {
color:#142533;
}
.galleries h4 a:hover {
text-decoration:none;
}
The issue you are running into with using only CSS is that there doesn't exist a CSS selector to select the previous or parent element. You can work around this stipulation if your images are going to be consistent sizes (height), you could put the <h4> ahead of the <div class="gallery-image"> and position it below the image with position: absolute; -- allowing your to use the CSS ~ selector to have hover events affect the image because it is after the element in the DOM. Also, I alleviated your white space selector issue with display: inline-block;:
<div class="gallery">
<h4>...</h4>
<div class="gallery-image">...</div>
</div>
.gallery {
position:relative;
}
.gallery-image:hover span {
display:block;
}
.gallery-image:hover img {
opacity:0.2;
}
.galleries h4 {
margin-top:5px;
line-height:27px;
display: inline-block;
position: absolute;
top: 230px;
}
.galleries h4:hover~.gallery-image img {
opacity:0.2;
}
.galleries h4:hover~.gallery-image span {
display: block;
}
-- I only included edited CSS above
JSFIDDLE
I'm bringing another answer, the symbol "+" also works when it comes to apply a style to an element of the same level in markup hierarchy :
The CSS modified :
.galleries h4:hover + .gallery-image img {
opacity:0.2;
}
.galleries h4:hover + .gallery-image span {
display: block;
}
It works only if the element we are targeting is immediatly positionned after the initial. In our case it works, just after h4:hover, we find .gallery-image.

Checkboxes styled like buttons hover and checked state css doesnt work Internet explorer

The checkboxes styled as buttons here do not show the blue colored hover state or light colored blue clicked state in Internet Explorer 8. They do not show the hover in IE9. Can you see what I can do to fix this?
I actually almost copied the CSS from here.
Buttons (checkboxes) and page I'm working on here: http://kodiakgroup.com/clients.php
My CSS for buttons (checkboxes):
#ck-button {
margin:4px;
background-color:#dff0ff;
border-radius:4px;
border:1px solid #D0D0D0;
overflow:auto;
float:left;
}
#ck-button label {
float:left;
width:12em;
}
#ck-button label span {
text-align:center;
padding:3px 0px;
display:block;
border-radius:4px;
}
#ck-button label input {
position:absolute;
top:-20px;
}
#ck-button input:hover + span {
background-color:#2f7fc7;
color:#fff;
}
#ck-button input:checked + span {
background-color:#97ceff;
color:black;
}
#ck-button input:checked:hover + span {
background-color:#2f7fc7;
color:#fff;
}
body { -webkit-animation: bugfix infinite 1s; }
#-webkit-keyframes bugfix { from { padding: 0; } to { padding: 0; } }

Resources