Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 1.85 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I make 2 elements share the same rollover state in CSS?
  2. <a class="close"><div class="closebutt"></div></a>
  3.  
  4. a.close {
  5.     float:right;
  6.     font-size:12px;
  7.     color: #a7dbe6;
  8.     text-decoration:underline;
  9. }
  10. a.close:hover  {
  11.     color: #fff;
  12. }
  13. a.vs_rewardClose:before {
  14.     content:"Close "
  15. }
  16. .closebutt {
  17.     background: url(images/close.gif) no-repeat;
  18.     display:inline-block;
  19.     width:14px;
  20.     height:14px;
  21. }
  22. .closebutt:hover {
  23.     background-position: 0px -14px;
  24. }
  25.        
  26. .close:hover > .closebutt {
  27.   background-position: 0px -14px;
  28. }
  29.        
  30. <a href="#" class="button">
  31.     <div class="glyph"></div>
  32.     <div class="text">Button text</div>
  33. </a>
  34.        
  35. <a href="#" class="button">
  36.     <span class="glyph"></span>
  37.     <span class="text">Button text</span>
  38. </a>
  39.        
  40. .button {
  41.   /* .. general style */
  42. }
  43.  
  44.   .button > .glyph {
  45.     /* .. general style for the glyph, like size or display: block */
  46.     background-image: url('..');
  47.     background-repeat: no-repeat;
  48.     background-position: left top;
  49.   }
  50.  
  51.   .button > .text {
  52.     /* .. general style for the text, like font-size or display: block */
  53.     text-decoration: none;
  54.   }
  55.  
  56.   .button:hover > .glyph {
  57.     /* .. change the glyph style when the button is hovered */
  58.     background-position: left bottom;
  59.   }
  60.  
  61.   .button:hover > .text {
  62.     /* .. change the text style when the button is hovered */
  63.     text-decoration: underline;
  64.   }
  65.        
  66. <a href="#" class="button red">
  67.     <div class="glyph"></div>
  68.     <div class="text">Button text</div>
  69. </a>
  70. <a href="#" class="button gray">
  71.     <div class="glyph"></div>
  72.     <div class="text">Button text</div>
  73. </a>
  74.        
  75. .button.red {
  76.   background-color: red;
  77. }
  78.  
  79.   .button.red > .text {
  80.     color: black;
  81.   }
  82.  
  83. .button.gray {
  84.   background-color: darkgray;
  85. }
  86.  
  87.   .button.gray > .text {
  88.     color: white;
  89.   }
  90.        
  91. .parent:hover > .text { your hover state}
  92. .parent:hover > .icon { your hover state}