Generate a see-through overlay when hovering over an image that matches the image's precise dimensions

I have encountered a challenge that I need help with. On a webpage, there are multiple images of varying sizes. I am looking to create a feature where hovering over an image triggers the appearance of a div above it containing a button and text without disrupting the layout. The button should be positioned above the text. Below is the code snippet I currently have on my page along with a link to a JSFiddle for reference:

Here is the JSFiddle.

<html lang="en">
    ...
</html>
.blurry-text {
    color: transparent;
    text-shadow: 0 0 5px rgba(0, 0, 0, 1);
}

...

.profileImage{
    border: 5px solid white;
}

I would like to achieve an effect similar to effect 13 on this webpage when hovering over the profile image:

Currently, creating the overlay div above the image causes unintended layout changes. Here are two screenshots showcasing the issue: https://i.sstatic.net/9pJkv.png https://i.sstatic.net/FOcCE.jpg

PS: Image Credit by Gerd Altmann from Pixabay

Answer №1

Allow me to address your query by making modifications to the current code snippet. Please refer to the updated code below:

.blurry-text {
    color: transparent;
    text-shadow: 0 0 5px rgba(0, 0, 0, 1);
}

.masthead{
    height: 100%;
    width: 100%;
    min-height: 500px;
    background: linear-gradient(to bottom,rgba(140, 140, 140, 0.31) 0,rgba(0, 0, 0, 0.8) 100%);
}

.fullPageImage{
    background: url(https://img.wallpapersafari.com/tablet/2560/1700/56/31/wC2k5O.jpg);
    height: 100%;
    width: 100%;
    background-size: cover;
    background-repeat: no-repeat;
}

.row{
    margin:0 !important;
}

.flex-column {
    max-width: 260px;
}

img {
    margin: 5px;
}

.scale {
    transform: scaleY(1.05);
    padding-top: 5px;
}

body,html {
    height: 100%;
}

.v-center {
    position: relative;
    transform: translatey(-50%);
    top: 50%;
}

.navbar-default{
    transition:100ms ease;
    background: #0000003b;
}
.navbar-default.scrolled{
    background:#000;
}

.label:after {
    content: '\A';
    white-space: pre;
}

.hideme{
    opacity:0;
}

@media (min-width: 992px) {
    .animate {
        animation-duration: 0.3s;
        -webkit-animation-duration: 0.3s;
        animation-fill-mode: both;
        -webkit-animation-fill-mode: both;
    }
}

@keyframes slideIn {
    0% {
        transform: translateY(1rem);
        opacity: 0;
    }
    100% {
        transform:translateY(0rem);
        opacity: 1;
    }
    0% {
        transform: translateY(1rem);
        opacity: 0;
    }
}

@-webkit-keyframes slideIn {
    0% {
        -webkit-transform: transform;
        -webkit-opacity: 0;
    }
    100% {
        -webkit-transform: translateY(0);
        -webkit-opacity: 1;
    }
    0% {
        -webkit-transform: translateY(1rem);
        -webkit-opacity: 0;
    }
}

.slideIn {
    -webkit-animation-name: slideIn;
    animation-name: slideIn;
}


.profileImage{
    border: 5px solid white;
}

#profilePicture{
display:inline-block;
background-image: url('https://img.wallpapersafari.com/tablet/2560/1700/56/31/wC2k5O.jpg');
background-size:cover;
background-repeat:no-repeat;
border: 5px solid white;
width: 12em;
height: 9em;
cursor: pointer;
}

.hoverLayout{
visibility:hidden;
position:relative;
height:100%;
width:100%;
}

#profilePicture:hover > .hoverLayout{
  visibility:visible;
  animation: slideIn ease-in-out .75s forwards;
}

.hoverLayout:hover{
  visibility:visible;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Discover Your PT</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>

<body id="page-top">
    <nav class="navbar navbar-default navbar-expand-sm navbar-dark fixed-top">
        <div class="container">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item active">
                    <a class="navbar-brand" href="../../index.html">Discover Your PT</a>
                </li>
            </ul>
            <ul class="navbar-nav ml-auto" id="ulNavBar">
                <li class="nav-item">
                    <a class="nav-link text-danger" href="../../php/view/loginSignup.html">Login</a>
                </li>
            </ul>
        </div>
    </nav>


    <header class="masthead">
        <section class="h-100 fullPageImage">
            <div class="row h-100 text-white font-weight-bold text-center">
                <div class="col-lg-12 h-50 my-auto">
                    <div class="profilePicture" alt="Profile Image" id="profilePicture">
                    <div class="hoverLayout">
                    <h1 class="text-uppercase border-bottom">
                        <span id="cognomeNome">Title</span>
                    </h1>
                    <h5>
                        <span id="descrizione">Description</span>
                    </h5>
                </div>
                </div>
                </div>
                <input type="file" name="upload1" id="uploadImageProfile" class="upload" multiple="multiple" />
                Maximum image size: 7mb

            </div>
        </section>
    </header>
</body>

</html>

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

Using jquery to create HTML elements but unable to remove them using jquery

I'm facing an issue with removing newly created li elements in an unordered list using jQuery. The delete button works perfectly fine for the existing li, but not for the ones added dynamically. <!DOCTYPE html> <html lang="en> <head> ...

What causes the website to malfunction when I refresh the page?

I utilized a Fuse template to construct my angular project. However, upon reloading the page, I encountered broken website elements. The error message displayed is as follows: Server Error 404 - File or directory not found. The resource you are looking fo ...

Tips for effectively utilizing the Material-UI Grid component to implement this layout

Currently, I am working on incorporating this design in Material-UI by utilizing the Grid component. To better delineate the boundaries, I have marked the container border in red for clarity. The Add button should be positioned at the far right of the c ...

Enhancing the appearance of a hyperlink heading

Seeking guidance on how to customize the title of a hyperlink. For instance, if I have a hyperlink structured like this: <a href="#" title="Hello">Click Here</a> Is there a way to alter the font style and size specifically for the word ' ...

Some elements are not responding to margin-top properly

I am facing a problem where 2 elements are not responding to the specified margins of margin: 260px 0 0 0; or margin-top: 260px;. Despite inspecting the elements in IE's dev tools and confirming that the margin is set, the elements appear at the top o ...

The HTML table fails to refresh after an Ajax request has been made

I am currently utilizing Ajax to delete a row from the Roles table. The functionality allows the user to add and delete roles using a link for each row. While the deletion process works properly and removes the row from the database, the table does not get ...

What is the best way to show and hide the information in a FAQ section when each one is clicked?

const faqItems = document.getElementsByClassName("faq-question"); const faqContents = document.getElementsByClassName("faq-content"); for (item of faqItems) { console.log(item); item.addEventListene ...

Enclose an image with a <div> element while maintaining the <div> height at

Encountering a challenge where positioning an element on top of an image at specific coordinates (20% from the top and 30% from the left) is required. Initially, the solution involved wrapping the image in a div with a relative position and using absolute ...

I incorporated a YouTube video using the iframe tag, but encountered an issue where the page would not scroll up or down when the mouse cursor was positioned on the iframe

How would you like your HTML code to function? When the cursor is on the iframe, do you want it to play a video? Also, should the parent page scroll when you scroll? <section class="section section-padding"> <div class="container"> ...

Create a unique design using two vertical sections with Bootstrap 5

I have been grappling with this issue for the past day, and I would greatly appreciate any assistance I can get! I am attempting to achieve a design similar to this using Bootstrap 5. Here is the goal I am aiming for While I have a good handle on creating ...

Steps to creating an elliptical border using CSS

Is there a way to apply CSS styles specifically to the left border of a div to achieve an elliptical shape, while keeping other borders normal? I've managed to create a semi-ellipse with the following code, but the rest of the border remains unchanged ...

Implementing the `columnChooser` functionality in Jqgrid with compatibility for Bootstrap 4

I'm currently incorporating jqgrid version 5.3+ into bootstrap 4, but I've encountered an issue with the columnChooser. The CSS styling doesn't display correctly because it doesn't match the bootstrap 4 theme. It works fine when I call ...

Save your canvas image as a file and attempt to force a download, only to be met with a failure to

Is there a way to save a canvas as an image file and allow users to choose the format (png or jpg) for download without saving the file on the server? Here's what I have tried: JavaScript Code: $.ajax( { type : "POST", url : "../php/downloa ...

An error was encountered at line 52 in the book-list component: TypeError - The 'books' properties are undefined. This project was built using Angular

After attempting several methods, I am struggling to display the books in the desired format. My objective is to showcase products within a specific category, such as: http://localhost:4200/books/category/1. Initially, it worked without specifying a catego ...

The screen reader is unable to interpret the text that is visible within the anchor tag

I have an Angular application with a dropdown menu implemented as shown below. When using the NVDA screen reader to navigate, only the content inside the aria-label attribute is being read when tab focused. However, I want it to also read the content (&ap ...

Arranging a pair of buttons from separate forms to be perfectly aligned on the same line

I have a page called edit.ejs for editing camps. This page contains two forms, one for submitting edits and the other for deleting the camp. Each form has a button, and they are currently displayed below each other. How can I align the buttons so that they ...

JavaScript is throwing an error when clicking on functions and managing the z-index property

I am experiencing difficulties with my website code. I have defined all the necessary functions and CSS, but I keep encountering errors such as "clicked is not defined," even though it is clearly present in the script. The goal of the code is to bring the ...

Bootstrap grid not maintaining consistent column widths

Currently, I am in the process of setting up a responsive bootstrap grid for the projects section on my portfolio page. My goal is to create a 3x3 grid that adjusts seamlessly for mobile devices and breaks down into a 2-column grid and eventually a 1x6 gri ...

Display the information stored in an array onto the console using console.log in Angular with Typescript

.html file <div class="container" *ngFor="let info of (this.info || [])"> <h5 class="card-title" (click)="getInfo()">{{info.paragraph1}}</h5> </div> .ts file getInfo () { *****console.lo ...

Steps for removing all inline styles within an element:1. Access the element's

I have a group of span elements containing texts generated by tinymce. <span class="ArticleSummary"> This content is produced using a text editor and may include various inline styles. </span> Typically, this text includes numerous inline s ...