• 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

    • FIFA cup is a worldwide event. Total global engagement — FIFA World Cup Qatar 2022 (official FIFA report) 5 billion people https://theworlddata.com/fifa-...-cup-viewership-statistics/ U.S., Canada, Japan drive vast World Series viewership for Games 1 and 2 In Japan despite a 9 a.m. local start time, Game One averaged 11.8 million viewers on NHK-G https://www.mlb.com/news/2025-...ching-large-global-audience There are also millions of annual viewers of the World Series in Latin America, especially Venezuela and the Domincan Republic due to the large number of players from those countries playing in the Major Leagues.
    • The original word arts were far more awesome! With their own preconfigured fill patterns, 3D layout, etc. I especially loved the ones circled below and still miss them from my primary school years: I frankly use them less these days 'cause the new one isn't as straightforward fine art as what we originally had. Same with the built-in picarts selection.
    • What didn't you understand about that was mainly referring to Google, Microsoft, etc. keeping your passwords. Password Management is a key service of Bitwarden and it's not going anywhere. In any case they do offer export to other Password management services, backup/download of passwords, and the already mentioned on-prem option. I don't agree with the OP to use the free option as it's better to be an actual customer IMO. They don't just don't delete accounts like the big tech companies with no recourse which was the main concern of this article. I was confused if the author was trying to sell this setup? It should be obvious to anyone reading this article this solution is overly complicated and overkill for most users.
    • I got this notification just now in Android: So I went in to disable the "Other" or "Marketing" notifications in Notifications management: But it came through the Now Playing? So if I disable that I no longer get what's Now Playing in Notifications? I'm a paying subscriber, not on the free plan... can they sink any lower?
    • Population especially in high density areas creates more heat and more humidity. This can be noticed in an indoor arena or concert room which heats up when the room or arena fills with people, without air conditoning to cool it down, Watering of lawns creates more humidity as the moisture from the watering rises into the atmosphere, creating a more humid condition. The again, depopulating an arena or room after an event will drop the temperature inside. Desert areas are less humid for a number of reasons, including a lower population density. Tel Aviv has horrible weather, unless you like it hot and humid. Summer days are regularly 90+ F with humidity well over 70%. It is probably not as bad as Mississippi but still it is bad enough.
  • 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
      504
    2. 2
      +Edouard
      163
    3. 3
      PsYcHoKiLLa
      91
    4. 4
      Steven P.
      75
    5. 5
      Michael Scrip
      72
  • Tell a friend

    Love Neowin? Tell a friend!