css - lighten background color on hover for different background colors -


i have multiple elements, background colors different each other. like:

<div class="element"> content of div</div> <div class="element2"> content of div</div>  .element{     width:100px;     height:50px;     background-color:#888888; } .element2{     width:100px;     height:50px;     background-color:#222222; } 

i want make hover like:

.element:hover, .element2:hover{} 

when bring mouse on element, background should little bit lighter. don't want use opacity: 0.4 (lightens whole div) or background-color:rgba(50,50,50,0.5); (only 1 color)

jsfiddle

the easiest way achieve apply background-image elements on :hover. either using css gradient (which generated using colorzilla's "ultimate css gradient generator"):

.element:hover, .element2:hover, .element3:hover {   /* permalink - use edit , share gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&0.5+0,0.5+100 */   background-image: -moz-linear-gradient(top, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);   background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(255, 255, 255, 0.5)), color-stop(100%, rgba(255, 255, 255, 0.5)));   background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);   background-image: -o-linear-gradient(top, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);   background-image: -ms-linear-gradient(top, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);   background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);   filter: progid: dximagetransform.microsoft.gradient(startcolorstr='#80ffffff', endcolorstr='#80ffffff', gradienttype=0); } 

.element {    width: 100px;    height: 50px;    background-color: #888888;  }  .element2 {    width: 100px;    height: 50px;    background-color: #222222;  }  .element3 {    width: 100px;    height: 50px;    background-color: #ff9900;  }  .element:hover,  .element2:hover,  .element3:hover {    /* permalink - use edit , share gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&0.5+0,0.5+100 */    background-image: -moz-linear-gradient(top, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(255, 255, 255, 0.5)), color-stop(100%, rgba(255, 255, 255, 0.5)));    background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);    background-image: -o-linear-gradient(top, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);    background-image: -ms-linear-gradient(top, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);    background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0.5) 100%);    filter: progid: dximagetransform.microsoft.gradient(startcolorstr='#80ffffff', endcolorstr='#80ffffff', gradienttype=0);  }
<div class="element">content of div</div>  <div class="element2">content of div</div>  <div class="element3">content of div</div>

or using partially-transparent image:

.element:hover, .element2:hover, .element3:hover {   background-image: url(http://i.stack.imgur.com/5udh0.png); } 

.element {    width: 100px;    height: 50px;    background-color: #888888;  }  .element2 {    width: 100px;    height: 50px;    background-color: #222222;  }  .element3 {    width: 100px;    height: 50px;    background-color: #ff9900;  }  .element:hover,  .element2:hover,  .element3:hover {    background-image: url(http://i.stack.imgur.com/5udh0.png);  }
<div class="element">content of div</div>  <div class="element2">content of div</div>  <div class="element3">content of div</div>

this works because of 'stacking' order of background properties; background-color sits @ , background-image sits 'above' layer.

references:


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -