Is there a way to show several elements simultaneously by hovering over another?

Can anyone help me with setting display:block; on all the p tags and the overlay div when I hover over my img tag? Is this achievable with just CSS or do I need to incorporate some JavaScript? Open to suggestions on the best approach. Any assistance would be greatly appreciated. Thanks.

.staff-pic-contain {
  height: 250px;
  width: 250px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.staff-pic {
  height: 100%;
  width: 100%;
  border-radius: 50%;
}

p {
  font-weight: bold;
  position: absolute;
  color: white;
  display: none;
}

.name {
  margin-top: 15%;
}

.number {
  margin-top: 25%;
}

.overlay {
  background-color: red;
  height: 100%;
  width: 100%;
  border-radius: 50%;
  position: absolute;
  top: 0;
  opacity: 0.75;
  display: none;
}

img:hover {
  cursor: pointer;
}
<div class="staff-pic-contain">
  <img class="staff-pic" src="https://picsum.photos/g/200/300" alt="">
  <p class="position"> CEO </p>
  <p class="name"> NAME </p>
  <p class="number"> 123123 </p>
  <div class="overlay"></div>
</div>

Answer №1

Utilize CSS to make the p and .overlay elements visible when hovering over the container:

.staff-pic-contain:hover p, .staff-pic-contain:hover .overlay {
  display: block;
}

To restrict the hover effect to the image, apply border-radius: 50% to the container.

Live Demonstration:

.staff-pic-contain {
  height: 250px;
  width: 250px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
}

.staff-pic {
  height: 100%;
  width: 100%;
  border-radius: 50%;
}

p {
  font-weight: bold;
  position: absolute;
  color: white;
  display: none;
}

.name {
  margin-top: 15%;
}

.number {
  margin-top: 25%;
}

.overlay {
  background-color: red;
  height: 100%;
  width: 100%;
  border-radius: 50%;
  position: absolute;
  top: 0;
  opacity: 0.75;
  display: none;
}

img:hover {
  cursor: pointer;
}

.staff-pic-contain:hover p, .staff-pic-contain:hover .overlay {
  display: block;
}
<div class="staff-pic-contain">
  <img class="staff-pic" src="https://picsum.photos/g/200/300" alt="">
  <p class="position"> CEO </p>
  <p class="name"> NAME </p>
  <p class="number"> 123123 </p>
  <div class="overlay"></div>
</div>

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

Calculate the length of a JSON array by using the value of one of its

What is the most efficient way to obtain the length of a JSON array in jQuery, based on the value of its attribute? As an illustration, consider the following array: var arr = [{ "name":"amit", "online":true },{ "name":"rohit", "online":f ...

JS problem with using for and foreach loops in Node.js

I've been really stumped by this situation. Everything was running smoothly until 4 days ago when two of my cron daemon jobs suddenly stopped working. Instead of ignoring the issue, I decided to take the opportunity to rebuild and enhance the code. I ...

Issue: Troubile in fetching CSS file from CDN and using local copy as fallback, What is the solution?

I previously inquired about this issue, however, I did not receive a satisfactory solution. Therefore, here I am asking again for your assistance. I am attempting to retrieve my CSS from an external CDN service, such as http://cdn.example.com/. This scrip ...

What is the best approach for running a database query using the value selected from a form dropdown?

Currently, my application server is ColdFusion and I am using SQL Server for the database. Within a select form element on my webpage, users can choose from a list of vehicles such as Volvo S60, BMW M6, and VW Jetta. Once a user selects a vehicle, I need ...

Enforce a limit of two decimal places on input fields using jQuery

Looking to limit an input field so that users can only enter numbers with a maximum of two decimals. Is it possible to achieve this using jQuery? Any way I could utilize the jQuery toFixed() function for this purpose? Thank you in advance! ...

The issue of background and footer distortion arises in PhoneGap when the keyboard is opened

Currently, I am experiencing screen problems with phonegap. The issue arises when a keyboard is opened, causing the back button at the bottom of the page to move above the keyboard and resulting in the background image appearing shorter. How can this be re ...

Utilizing ng-repeat, filter, and the uib-popup-datepicker to refine and display specific data within a table column

I'm currently facing a common scenario in my Angular application where I need to filter items from an ng-repeat using an HTML5 input of type 'date' or Angular-UI-Bootstrap's 'uib-popup-datepicker'. Despite extensive research, ...

Can you override CSS background image styles to ensure both images are loaded?

Suppose there are 2 CSS styles that assign background images to an element, and one style overrides the other. In this scenario, will both images be downloaded by the browser or just the overriding one? I am asking this because I recently participated in ...

How can we develop play buttons for Facebook timelines similar to those found on Spotify?

Is it possible to create an HTML5 player that can be embedded on Facebook timelines, similar to the way Spotify has special privileges as a Facebook partner? I'm looking to provide a list of play buttons that, when clicked, will play songs sequentiall ...

Alternate Row Colors Using Odd/Even CSS Styling for Main Headings

In my expand/collapse table, I have set up alternating row colors (dark grey and light grey) that adjust automatically when expanding or collapsing. The challenge I'm facing is that for certain rows, I want to apply a specific background color using ...

Expansive dropdown in Bootstrap 5

My navbar currently has a mega menu dropdown for 'products', but I want this dropdown to take up the entire width of the screen to accommodate more items. However, my CSS modifications did not produce the desired result. On large screens, it fail ...

Looking to develop a method that extracts a value from an array, saves it, and transfers it to another array exclusively through the use of .pop and .push methods

I'm currently working on an assignment for my JS course that involves creating a function using only .push and .pop commands. The task is to take the last value from the first array and move it to the second array. Unfortunately, I seem to be messing ...

Tips for eliminating the gap separating the authentication design from the additional elements within the Laravel, Vue, and Inertia framework

I'm currently working with Laravel and Vue using Inertia. When I log into the system, the authentication layout creates a space at the top of the page. How can I resolve this issue? Here is an image highlighting the space I need to remove, marked wit ...

When using Typescript with Mongoose, you may encounter the error message "Property 'x' does not exist on type 'Document'"

Here is my custom Mongoose model used in conjunction with TypeScript: import mongoose, { Schema } from "mongoose"; const userSchema: Schema = new Schema( { email: { type: String, required: true, unique: true, lowerc ...

Ionic - encountering crashes with ion-nav-view on emulator

I am encountering an issue with ion-nav-view. Whenever I try to use it, the emulator displays a black screen, but it works perfectly fine in ionic serve. I suspect it may be a syntax error causing this problem. Interestingly, when I create a blank projec ...

Angular2: Issue encountered while processing click event

When I click a button on my client application, it sends a request to the server I created using Express. The request handler in the server simply logs 'Delete from server' every time the button is clicked. I am encountering these errors when cl ...

Moving the panel to follow the mouse cursor in Firefox Add-on SDK

Is there a way to show a panel on the screen at the exact position of the mouse? I'm finding it difficult to understand how to change the position of the panel in Firefox SDK, as the documentation lacks detailed information. ...

Transferring data between two screens within an Ionic app by harnessing the power of angularJS

As a beginner in Ionic and Angular development, I am currently facing an issue with my Ionic application. I have two pages - one with drop-down selects and a submit button, and another page to process the user's choices and display the results. The pr ...

Issues with CSS and JavaScript functionality persist within the Flask framework

Having trouble with CSS and JavaScript on my website hosted via Flask framework on PythonAnywhere. Here is the directory structure: home/dubspher/mysite/ - README.md - app.py - index.html Static/ - css - fonts - images - js - sass Original HTM ...

Issue with integrating React, Material UI, Typescript, Webpack, and server-side rendering (SSR

I encountered an issue with my server-side rendered app when I tried to integrate Material UI into it. Here is how my directory structure looks: app/ build/ * This directory is generated by webpack server_bundle.js public/ ...