• 0

Hover issues changing an icon to text


Question

I'm having coding issues with creating a hover effect for icons. I want to change the icon into specific text when hovered over, but I'm not getting any results.

 

HTML:

 

<!--Interactive Squares-->
            
    <div class="small-boxes">
        <p class="tips-icons"><i class="icon-sun-o"></i></p>
    </div>
            
    <div class="small-boxes"><p class="tips-icons"><i class="icon-umbrella-weather"></i></p></div>
    <div class="small-boxes"><p class="tips-icons"><i class="icon-squirrel"></i></p></div>
    <div class="small-boxes"><p class="tips-icons"><i class="icon-cloud"></i></p></div>
    
            
            
   <!--Hover Action-->
      <p class=text1>Gardening for Sunshine</p>  
      <p class=text2>Gardening for Rain</p>
      <p class=text3>Avoid the Squirrels</p>
      <p class=text4>Gardening for Shade</p>
            
    <!-- End of Hover Action-->

 

 

 

CSS:

.clear {
    clear: both;
}
.last {
    margin-right: 0;
    
    
}
.tips-icons {
    color: green;
    font-size: 85px;
    letter-spacing: 30px;
    margin: 30px 20px 20px 60px;
   
}
/* Hover Action */
.tips-icons: hover .text1 { 
    opacity: 0.6; 
    text-align: justify; 
    color: green; 
    font-size: 20px; 
    font-weight: 700; 
    font-family:'Roboto', sans-serif; 
    padding:30px; 
}
.text1 { 
    width: 200px; 
    height: 150px; 
    background: #FFF;
    color: green;
    opacity: 0; 
} 
.text2 { 
    width: 340px; 
    height: 217px; 
    background: #FFF; 
    color: green;
    opacity: 0; 
} 
.text3 { 
    width: 200px; 
    height: 150px; 
    background: #FFF;
    color: green;
    opacity: 0; 
} 
.text4 { 
    width: 200px; 
    height: 150px; 
    background: #FFF; 
    color: green;
    opacity: 0; 
} 

/* ---End of Hover Action--- */
.small-boxes {
    border-radius: 25px;
    background: white;
    padding: 20px; 
    width: 200px;
    height: 150px;
    float: left;
    margin: 40px 40px 30px 80px;
    box-shadow: 10px 10px 5px #bfbfbf;
    border: solid 8px #99ff99;
    
}

            

Edited by Mur
Wrapping code in formatted tags

2 answers to this question

Recommended Posts

  • 0

Hi,

 

You might want to do a little bit of reading how CSS works.

 

.tips-icons: hover .text1

 

This selector won't do anything for two reasons:

 

You have a space between : and hover .. CSS now thinks 'hover' is it's own selector... well it would if it wasn't incorrect syntax.

 

It should be .tips-icons:hover

 

Also, you have written it in a way that .text1 must be a child of .tips-icons like so:

 

<p class="tips-icons">

  <p class=text1>Gardening for Sunshine</p>  

</p>

 

The next problem you have is, CSS is not directly able to replace the content of 1 div with another div, unless you overlay them together and hide one as you show the other on hover... not ideal. Another method with CSS is to use the content: "something..." css property... but the content will be in CSS and not HTML, so it may not be viable depending on use case.

 

So, lets go with what you already have. Moved your text1/2/3/4 divs inside your boxes and we'll hide one, and show the other on hover.

 

You are also repeating the same code over and over, you don't need to repeat CSS for the same selector (text1, text2, text3, text4) you could just call them text.

 

Also, they aren't paragraphs, so no need to use P.

 

    <div class="small-boxes">
        <i class="fa fa-close"></i>
        <span>Gardening for Sunshine</span>  
    </div>
            
    <div class="small-boxes">
        <i class="fa fa-close"></i>
        <span>Gardening for Rain</span>
    </div>
    
    <div class="small-boxes">
        <i class="fa fa-close"></i>
        <span>Avoid the Squirrels</span>
    </div>
    
    <div class="small-boxes">
        <i class="fa fa-close"></i>
        <span>Gardening for Shade</span>
    </div>

 

i {
    color: green;
    font-size: 85px !important;
    padding-top: 25px;
}

.small-boxes {
    border-radius: 25px;
    background: white;
    width: 200px;
    height: 150px;
    line-height: 150px;
    text-align: center;
    float: left;
    margin: 40px 40px 30px 80px;
    box-shadow: 10px 10px 5px #bfbfbf;
    border: 8px solid #99ff99;
}

span {
    color: green;
    display: none;
}

.small-boxes:hover i {
  display: none;
}

.small-boxes:hover span {
  display: inline;
}

 

Here is an example of the above code in action: https://jsfiddle.net/LjaL19uf/

 

The only thing you need to do is change your icons back.

This topic is now closed to further replies.
  • Posts

    • Interesting image choice... reminds me of the human centipede poster
    • Get $50 of aloSIM Mobile Data Traveler eSim credit for just $24.97 by Steven Parker Today's highlighted deal comes via our Apps + Software section of the Neowin Deals store, where you can save 50% off aloSIM Mobile Data Traveler Lifetime eSim Credit: Pay $24.97 for $50. Stay connected affordably in 120+ countries/regions with your own lifetime eSIM! An eSIM is a digital SIM card. It's basically just mobile data. Once it's activated on your device, it can connect you to data networks in other countries – giving you an internet connection with NO roaming charges. With aloSIM, you can load prepaid eSIM data packages onto your phone, tablet, or computer. Your lifetime eSIM never expires, so it's yours forever and there are never any monthly charges. You'll get $50 in eSIM data credit, which is almost always enough to cover all your data roaming needs for a full year. But if you run out of data, you can always top up your lifetime eSIM and stay connected internationally. Pay $24.97 for a lifetime eSIM with $50 in travel data credit Use your eSIM to join data networks in 120+ countries Install your lifetime eSIM on a compatible device to roam on local data networks Your lifetime eSIM never expires, and can be topped up with more data anytime Many data packages cost as little as $4.50 and last 7 days. Depending on the package you choose, the length of time varies. Good to know Length of access: lifetime For NEW customers only Instant digital redemption Once you add your $50 credit to your aloSim account you have up to 12-months to use it — after that your credit will expire When you pay for a data plan you also get a free phone number (via Hushed) for the same duration of your plan that was purchased - IE 7 day eSim plan gives you a free 7-day phone number Purchased coupon must be redeemed and used within 12 months This deal is not stackable (one offer per aloSIM account) A $4.50 data package will last 7 days The data DOES expire, and you WILL NOT have any leftover data for your next trip unless it takes place within the validity period. While the eSIM never expires, the actual data package is only valid for the length of time stated at purchase (i.e. seven days after activation, 30 days after activation, etc.) So if you buy a seven-day package and only use a tiny bit, that package is still going to expire after seven days. Access options: mobile (check compatibility) Max number of device(s): 1 Updates included Here's the deal: This aloSIM Mobile Data Traveler eSim $50 Credit normally costs ... $50, but it can be yours for just $24.97 for a limited time, a saving of $25 (50% off). For specifications, and license info please click the link below. Get this aloSIM Mobile Data Traveler eSim for just $24.97 (was $50) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • WordArt was cool. We now have color fonts as a substitute although Word only supports COLRv0 and COLRv1 (Fraud OS 11 only). The OpenType SVG color font format needs to be supported by Office. Adobe's apps support it
  • Recent Achievements

    • First Post
      DrWankel earned a badge
      First Post
    • Reacting Well
      DrWankel earned a badge
      Reacting Well
    • Week One Done
      Supreme Spray LV earned a badge
      Week One Done
    • One Month Later
      Genuinetonerink- Dubai earned a badge
      One Month Later
    • Week One Done
      Genuinetonerink- Dubai earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      498
    2. 2
      +Edouard
      158
    3. 3
      PsYcHoKiLLa
      90
    4. 4
      Steven P.
      74
    5. 5
      Michael Scrip
      72
  • Tell a friend

    Love Neowin? Tell a friend!