What is the best way to display text on all cards when hovering over them with the cursor?

I've been attempting to make all three cards reveal text upon hovering over them with the mouse pointer. However, I'm facing an issue where only the text in the first card on the left is displayed, while the other two cards remain unaffected, despite having added lorem ipsum text to all three divs for the cards.

I've scoured the internet for solutions but haven't come across anything that resolves this specific problem. It seems like I may need to incorporate a JavaScript loop to iterate through it, but I'm struggling to figure out how to implement this.

HTML

<div class="wrapper">
  <div class="card" id='card'>
    <div class="orangeCover">
      <p id="hidden" class='easein'>Lorem ipsum dolor sit amet, 
        consectetur adipisicing elit. Ipsa, eaque.
      </p>
    </div>
  </div>
  <div class="card" id='card'>
    <div class="orangeCover">
      <p id="hidden" class='easein'>Lorem ipsum dolor sit amet, 
        consectetur adipisicing elit. Ipsa, eaque.
      </p>
    </div>
  </div>
  <div class="card" id='card'>
    <div class="orangeCover">
      <p id="hidden" class='easein'>Lorem ipsum dolor sit amet, 
        consectetur adipisicing elit. Ipsa, eaque.
      </p>
    </div>
  </div>
</div>

CSS


html,
body {
  margin: 0;
}

.wrapper {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-column-gap: 20px;
  grid-row-gap: 20px;
  grid-template-columns: auto auto auto auto;
}

.orangeCover {
  width: 250px;
  height: 250px;
  position: absolute;
}

.orangeCover:hover {
  background-color: orangered;
  transition: ease-in 0.5s;
}

.card {
  border: 2px orangered solid;
  width: 250px;
  height: 250px;
  margin-left: 100px;
  margin-top: 100px;
  background-image: url("http://source.unsplash.com/random/250x250");
}

#hidden {
  visibility: hidden;
}

.reveal {
  margin-left: 20px;
  color: white;
  font-size: 1.5rem;
}

Javascript


let text = document.querySelector("#hidden"), i;
let overlay = document.querySelector(".card");
let hiddenOverlay = document.querySelector(".card");

overlay.addEventListener("mouseover", newOverlay);
hiddenOverlay.addEventListener("mouseleave", hidden);

function newOverlay() {
  text.style.visibility = "visible";
  text.className = "reveal";
}

function hidden() {
  text.style.visibility = "hidden";
}

Answer №1

I decided to switch the IDs such as hidden and transformed them into classes in the section below.

Check out the snippet on JSFIDDLE.

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

Troubleshooting the Issue with Jquery Menu and Mouse Pointer

Recently, I've been attempting to modify the cursor behavior on a navigation menu that I stumbled upon at HTML Drive's JQuery Menu. I experimented with CSS and jQuery. In my JQuery attempt, I utilized... $("body").hover(function() { $(this).cs ...

Is the JSON output created by Python's json.dumps function secure for use in JavaScript?

I'm curious to learn if the output of Python's json.dumps method can be safely rendered directly into HTML/JS script without needing to escape it. my_dict = {...} my_dict_json_str = json.dumps(my_dict) and then incorporating this: <script&g ...

Integration of Angular.js functionalities within a Node.js application

After working on my node.js app for a few weeks, I decided to add some additional features like infinite-scroll. To implement this, I needed to use packages in node.js along with angular.js. So, I decided to introduce angular.js support to the app, specifi ...

Attempting to display divs at the bottom when hovering over menu options

I need help troubleshooting my HTML and CSS code. I want to be able to hover over a menu item and have the corresponding div appear at the bottom. Can you point out what's wrong with my code? <!DOCTYPE html> <html> <head> &l ...

Empty req.params in nested ExpressJS routers

I have a unique routing system that relies on the directory structure of my 'api' folder to automatically configure routes. However, I encountered an issue where the req.params object is undefined in the controller when using a folder name as a r ...

Error: the function method is not declared in the JavaScript/jQuery code

Within my main.js file, there is a method outlined as follows: ;(function ($, window, document, undefined) { 'use strict'; var testing = function(d) { //irrelevant code }; })(jQuery, window, document); In the HTML of my pr ...

Reasons why the Express Route fails to store cache while executed in a separate file

My code works fine when it's all in one file, but the caching stops working when I move it to a separate middleware file. Can someone help me understand why the caching isn't functioning properly in my middleware? Here is the working code: var e ...

How can I trigger HierarchicalDataSource.read() when the kendoDropDownList's change event is fired?

Currently, I am utilizing the treeview and HierarchicalDataSource features of KendoUI. Additionally, I have included a kendoDropDownList at the top of the page. Each time a user changes the value of the dropdown list, it triggers the 'change' eve ...

Behavior of page scrolling in an ASP.Net web forms application with Bootstrap integration

Encountering a problem with page scrolling behavior in an ASP.Net web forms application when using Bootstrap CSS. Here's what's happening: Started a new Web Forms project in Visual Studio 2022 Visual Studio set up the project with necessary fold ...

Adjust item size and move them into the panel

I am looking to create a panel that arranges items in a specific layout shown here: https://i.stack.imgur.com/qw3lS.png Below is the code I have attempted so far: import React, { useCallback, useEffect } from "react"; import { Box, Grid, Tab, T ...

Enhance Your Website's User Experience with Jquery Link Click

In the layerslider, I have a form where users must fill out the current page to move to the next one. Initially, I tried showing and hiding the button, but it confused my users. Now, I am changing the opacity and clickability of the buttons based on page ...

confirming the phone field's character count

My website has multiple phone fields, each formatted like this: $("#HomePhoneInput").inputmask({ "mask": "(999) 999-9999" }); $("#WorkPhoneInput").inputmask({ "mask": "(999) 999-9999" }); $("#CellPhoneInput").inputmask({ "mask": "(999) 999-9999" ...

jQuery when - anticipate the fulfillment of multiple success/done callbacks

When using $.when to determine when an array of ajax promises are finished, I have noticed that although the ajax calls themselves are completed when $.when fires, their callbacks and done functions are not. How can I make sure to wait for the callbacks to ...

The issue with the page not appearing correctly on IE9 is currently being resolved

I am utilizing bootstrap alongside a bootswatch theme and HTML5 boilerplate to design a webpage. While it appears correctly on Chrome and Firefox, the display is off on IE9 and IE8 mode. However, everything works fine when compatibility mode is enabled in ...

Tips for Keeping Vuetify Dialog Title at the Top and Ensuring Buttons are Always Visible

My goal was to make the Vuetify dialog title and content headers stay fixed at the top while scrolling. I attempted using "style:position:fixed". However, when I scroll, the headings go out of view. Below is the current code: <v-layout row wrap ...

I am looking to incorporate a 10 px border at the top of my column by utilizing bootstrap4

How can I add a border to the top of my column using Bootstrap 4? I've been struggling with it and can't seem to get it right. Here is the code I'm currently using, which includes <div> tags for the columns: <!doctype html> &l ...

Excluding numerical values from an array using JavaScript

I have been working on a code snippet to filter out numeric values from an array, but instead of getting only the numbers, I am receiving the complete array. I am unable to identify where the issue lies in my code. Can someone please assist me as I am cu ...

Creating a cascading select menu based on the selected value of another select menu

I am in the process of creating a menu that displays two lists for regions: one <select> for selecting the region and another <select> for choosing from available municipalities within that region. I have set up a <form> and I utilize Jav ...

Extract data from JSON using the parse function

After utilizing the function JSON.stringify(), I have obtained this JSON: {"get":"function (f,g){'use strict';var h,i;if(i={},'string'==typeof f){if('object'==typeof g)for(h in g)i[h]=g[h];i.url=f}else if('object'== ...

Adjust the placement of a dropdown menu placed within a table

I have successfully implemented a sticky table header, but I am encountering an issue with the select element integrated into my table: View before scrolling the table View after scrolling the table As you can see, the select element overlaps with the t ...