When hovering over an image, CSS text will be displayed

Creating a CSS hover effect where text appears when the user hovers over a small thumbnail and a large image is displayed upon clicking. I have set up a modal for the image, but having difficulty with positioning the text. Currently, the text is located under the image and always visible. My goal is to center the text on the image and only display it when the user hovers over the image.

CSS

      
      <!-- filter style -->
      <link rel="stylesheet" href="css/style.css"> 
      <!-- modal style-->
      <link rel="stylesheet" href="css/w3.css">

        /* image style*/
         #wrapper{
            position:relative;
            
        } 

       /* text style*/
        #wrapper p{
            z-index:100;
            position:absolute;
            top:50%;
            left:90%;
            visibility:hidden;
            font-family:'Alegreya', serif;
            opacity: 0;
            color:white;
            }
    
        
         #wrapper:hover #wrapper p{
              visibility: visible;
              opacity: 1;
            }
        
       
HTML

        <section class="cd-gallery">
<ul>
<li class="mix color-1 check1 radio2 option3">
                   <div class="wrapper">
                    <img src="http://cfile1.uf.tistory.com/image/255D8B4E51ADD7CD04EF09" alt="Image 1" style="width:100%;cursor:zoom-in"
                         onclick="document.getElementById('modal01').style.display='block'"/>
                             <p class="text">Band<br>Portrait</p></div> 
                    
                    <div id="modal01" class="w3-modal" onclick="this.style.display='none'">
                       <span class=" w3-padding-16 w3-display-topright">&times;</span>
                     <div class="w3-modal-content w3-animate-zoom">
                       <img src="http://cfile1.uf.tistory.com/image/255D8B4E51ADD7CD04EF09" style="width:100%">
                      </div>
                  </div>
                       
 
                  </li>
              </ul>
           </section>

Answer №1

Include these guidelines in your file

.text {
  opacity: 0;
  display: inline-block;
  text-align: cen;
  position: relative;
  left: 50%;
  transform: translate(-50%);
  -webkit-transform: translate(-50%);
  -moz-transform: translate(-50%);
  -ms-transform: translate(-50%);
  -o-transform: translate(-50%);
}
.wrapper:hover .text {
  opacity: 1;
}

Please note that the transform property may not be supported by older browsers

View the code snippet below

<!-- filter style --> <link rel="stylesheet" href="css/style.css"> <!-- modal style--> <link rel="stylesheet" href="css/w3.css">
/* image style*/

#wrapper {
  position: relative;
}
/* text style*/

#wrapper p {
  z-index: 100;
  position: absolute;
  top: 50%;
  left: 90%;
  visibility: hidden;
  font-family: 'Alegreya', serif;
  opacity: 0;
  color: white;
}
#wrapper:hover #wrapper p {
  visibility: visible;
  opacity: 1;
}
.text {
  opacity: 0;
  display: inline-block;
  text-align: cen;
  position: relative;
  left: 50%;
  transform: translate(-50%);
  -webkit-transform: translate(-50%);
  -moz-transform: translate(-50%);
  -ms-transform: translate(-50%);
  -o-transform: translate(-50%);
}
.wrapper:hover .text {
  opacity: 1;
}
HTML

<section class="cd-gallery">
  <ul>
    <li class="mix color-1 check1 radio2 option3">
      <div class="wrapper">
        <img src="http://cfile1.uf.tistory.com/image/255D8B4E51ADD7CD04EF09" alt="Image 1" style="width:100%;cursor:zoom-in" onclick="document.getElementById('modal01').style.display='block'" />
        <p class="text">Band
          <br>Portrait</p>
      </div>

      <div id="modal01" class="w3-modal" onclick="this.style.display='none'">
        <span class=" w3-padding-16 w3-display-topright">&times;</span>
        <div class="w3-modal-content w3-animate-zoom">
          <img src="http://cfile1.uf.tistory.com/image/255D8B4E51ADD7CD04EF09" style="width:100%">
        </div>
      </div>

    </li>
  </ul>
</section>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to update a ko.observable in Durandal from a different view?

Essentially, my goal is to achieve the following: In the main.html file: <div style="cursor:pointer" data-bind="compose: {model: $data, view: "child.html"}" /> <div style="background-color:#CCC; cursor:pointer; width:45px;" data-bind="visible: s ...

Issue arising from changing classes in Internet Explorer

I've encountered an issue where I am trying to change the class of an element on a mouseover event, but it doesn't seem to fire as expected. However, when I add an alert in the function, it suddenly works. Here is the code that doesn't work ...

Sprockets could not locate the file for jquery.atwho

I have been attempting to integrate the jquery-atwho-rails into my application, a Rails gem designed for at.js. I have followed all the steps provided, executed bundle install, included the necessary code in both application.js and application.css, stopped ...

Switch out the arrow icon in the dropdown menu with an SVG graphic

Looking for a way to customize the dropdown caret in a semantic-ui-react component? Here's how it currently appears: <Dropdown className="hello-dropdown" placeholder="Comapany" onChange={this.someFunction} options={som ...

Using jQuery to toggle the image of a button based on its id

I have a jQuery function that opens another section when clicking on a div with the class 'open', and changes the image of a button by switching its id for CSS. However, I now need to change the button's image back when it is clicked again. ...

There seems to be a lack of information appearing on the table

I decided to challenge myself by creating a simple test project to dive into Angular concepts such as CRUD functions, utilizing ngFor, and understanding HttpClient methods (specifically get and post). After creating a Firebase database with an API key and ...

Adding an active class to a large image when a thumbnail image is clicked can enhance user experience and

I've created a photo gallery using jquery. Currently, when I click on "next", the image changes based on the index. However, I also want to be able to click on the thumbnails (small images) and display the larger image according to that specific inde ...

The datepicker feature mysteriously vanishes when using Safari browser

When I utilize the jquery ui datepicker (range) and open my datepicker, if I scroll down the page, the calendar disappears. This issue seems to only occur on Safari browsers with mobile devices. Has anyone else experienced this problem? Would someone be ...

Having trouble with the display of styles on Material UI Cards?

I am currently attempting to customize the default Material UI classes by using useStyles and applying a classname of titleSection. My goal is to make the titleSection bold and in Roboto font, but unfortunately, those styles are not being applied. Below i ...

How come the CSS for my angular ngx-mat-datetime-picker and mat-datepicker collide when they are both present on the same page?

Within the same form, I have two input fields stacked under each other. One is an ngx-mat-datetime-picker and the other is a mat-datepicker. Individually, they function correctly. However, when I open them for the second time, the one I opened first appear ...

Add Text to Bootstrap Modal Window

The bootstrap modal body is not containing all of my content and some of it is overflowing. <div class="modal fade" tabindex="-1" role="dialog" id= "blockModel"> <div class="modal-dialog"> <div class="modal-content"> < ...

What is the method for updating the form action to alter the hash without causing a page reload?

My website is designed to show dynamic data based on the information following the '#' in the URL. Surprisingly, when I manually change this value in the URL, the page doesn't reload. However, if I modify it within a form on the site, the we ...

What is the best way to reposition the caret within an <input type="number"> element?

How can I make the caret move when an input is clicked? The code I found works with text, but not with number. Also, is there a way to pass the length without specifying a value (e.g. 55) in the parameters? HTML <input type="number" name="cost" value= ...

What is the maximum width allowed for a WordPress site on mobile devices?

I have been tasked with addressing the responsiveness issues on mobile for this particular site. However, I am struggling to understand why the website is displaying horizontal scrolling on the landing page in a mobile view. Any assistance in resolving t ...

The compatibility between an Ajax client and a Django server across different domains is only possible when using JSONP

Currently, our Django application is functioning on tomcat with Basic Authentication. I am interested in making cross-domain requests, and have found that it only works when using $.ajax({...dataType: 'JSONP',...}). The use of dataType: JSON does ...

What could be the reason behind the improper display of JavaScript for ID overlay2?

Why is it that when I try to have two overlays with different messages display upon clicking buttons, they both end up showing the same message? Even after changing the ID tag names, the issue persists. Can someone shed some light on what might be causin ...

What could be the reason for the malfunction of the min value in my Material UI date textfield?

I am attempting to set a minimum date for the picker to start from, but it does not seem to be working as expected. <TextField id="date" type="date" defaultValue="2017-05-24" minDate="24/01/2019" ...

Issue with calling a function to change the CSS color class of a button in Angular

Within my Angular code, I am attempting to set a CSS color for my button by calling a TypeScript function that will return the appropriate CSS class name. This is the code I have tried: <button style="height: 10%" class="getColor(days.date)">{{days ...

jQuery not functioning properly when attempting to add values from two input boxes within multiple input fields

I am facing an issue with a form on my website that contains input fields as shown below. I am trying to add two input boxes to calculate the values of the third input box, but it is only working correctly for the first set and not for the rest. How can ...

My jQuery does not function correctly when I try to set a variable

Presented below is a crucial function: <script type='text/javascript'> $('#clicktogohome').live('click', function(){ history.pushState({}, '', this.href); popstate(this.href); return false; }); $('# ...