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:

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

Customizing CSS in Angular Components: Taking Control of Style Overrides

I am new to working with Angular and HTML. Currently, I have two different components named componentA and componentB, each having their own .html, .css, and .ts files. In the componentA.css file, I have defined some styles like: .compA-style { font- ...

Teaching jQuery selectors to detect recently-added HTML elements

Unable to find a solution in the jQuery documentation, I am seeking help here for my specific issue. Embracing the DRY principle, I aim to utilize JavaScript to include a character countdown helper to any textarea element with maxlength and aria-described ...

Checkbox ensemble computes total score

I am currently working on a project that involves multiple checkbox groups, with each group containing 3 checkboxes labeled as (1, X, 2). My goal is to assign a value of 100% to each group, distributed evenly among the checkboxes within it. The distributio ...

"In the shadows, the .toLowerCase() method of undefined is failing without making a sound, yet the code

It seems that letting things fail in the background is necessary for this example to work consistently. Is there a way to work around this issue? There are instances where I need to check a div with a data-attribute on certain pages and add a class if it ...

Adding multiple elements with varying content to a separate division

I am attempting to combine two div elements into a single div, but I'm encountering difficulties. Despite thoroughly examining my code, everything appears to be correct. Here's what I've tried so far. To assist me in achieving this, I am ut ...

Tips for concealing overflowing CSS content

How can I prevent CSS content from overflowing? I am trying to display a price tag in the CSS element, but it is protruding out of my card. .content{ content:''; position: absolute; left: 309px; ...

"Upload a text file and create a JavaScript variable that contains the text within it

I am currently developing a library and I need to add a feature that reads the contents of a text file. Currently, it only returns the path. How can I modify it to return the actual content of the file? function displayFileContent() { var file = do ...

JSX Bootstrap unresolved arror

I have been using Bootstrap with React, but the compiler keeps failing due to unterminated JSX contents. I have checked my code numerous times and can't seem to find any unclosed tags no matter how the ternary operator evaluates. As a beginner in Reac ...

What could be causing the CSS transition to fail when the menu button is clicked?

After clicking on the menu, a class 'active' is added to both the 'div' and 'section' elements. https://i.stack.imgur.com/jbamR.png The following javascript code accomplishes the above functionality: <script> const ...

Adjusting div to not be absolutely positioned

Trying to create a div with animated borders, but it only works when positioned absolutely in the center. For illustration, here is the HTML and CSS code: .bb, .bb::before, .bb::after { position: absolute; top: 0; bottom: 0; left: 0; right: 0; ...

Struggling to create horizontal buttons for my design

Does anyone have any suggestions for fixing my navigation bar? I attempted to create it myself, but I'm struggling to make everything function properly. https://i.stack.imgur.com/h4yA1.jpg Below are the images of the button in all three states: htt ...

Harnessing the power of flexbox for data visualization

Trying to use flexbox to display data from a dataset in my code. Here is the code snippet: <div ng-app="myapp" ng-controller="FirstCtrl"> <div ng-repeat="name in names" class="graph-wrapper"> <div class="aside-1 content"> ...

Updated INNER header and footer - unrelated to the answered questions

After observing, the inner-header and inner-footer div scroll along with the area that contains the select list. How can I make that area scroll down while keeping the inner-header/footer fixed within the content? I hope my query is understandable. Thank ...

Using Node.js to retrieve table data from a URL

My journey with Node JS and express is just beginning as I dive into building a website that serves static files. Through my research, I discovered the potential of using NodeJS with Express for this purpose. While I have successfully served some static HT ...

Arrange a variety of images with different dimensions in a narrow row while keeping the width fixed and adjusting the height accordingly

Imagine you have a collection of 3 (or more) images, each with different sizes and aspect ratios, within a fixed-width div (for example width:100%): <div class="image-row"> <img src="1.png"> <img src="2.png"> <img src="3.png" ...

Bring in the content to Notepad utilizing jQuery

How can I export data to Notepad? I have fields for Name, Age, and WorkingStatus that are input as text and textarea. Is there a demo or code available to help me insert this data into Notepad? ...

Fixed position of the element within a parent stacking context

How can I ensure that the #icon appears below the #dropdown in the following example? https://i.stack.imgur.com/GoBcR.png The position: fixed of #container seems to be creating a new stacking context for its children. Changing the position value fixes th ...

Issue with Jquery .scroll method not triggering display:none functionality

Styling Using CSS #acc-close-all, #to-top { position: relative; left: 951px; width: 29px; height: 42px; margin-bottom: 2px; display:none; } #acc-close-all a, #to-top a { position: absolute; float: right; display: block ...

Hide all elements in jQuery that do not have a class assigned

I've implemented a straightforward jQuery script that toggles the "active" class on an li element when it is clicked: $('li').click(function() { $(this).toggleClass('active'); }); My goal is to hide all other li elements in t ...

Is it possible to modify the variables in a SCSS file within an Angular 2 project?

Currently, I am working with Angular 2 using a SCSS style. My challenge is to retrieve data from a server in order to change a specific variable within the component's style - specifically a percentage value. You can view the SCSS and HTML code here. ...