Extend the div container upwards while keeping the baseline intact

When hovering over a particular div, a child div expands from the bottom to reveal its hidden contents. However, there is an issue where the parent div seems to shrink slightly from the bottom, causing elements below it to shift upward.

For a visual demonstration of this behavior, check out this fiddle.

body {
  color:white;
}

.game-thumbnail {
    background-color: rgba(23, 30, 26, 0.95);
    margin-top:-15%;
    position:relative;
    z-index:1;
    padding:0.5em 1em;
    transition: margin 0.333s ease-out, padding 0.333s ease-out;
}

.game-entry {
    cursor:pointer;
    width:66vw;
    max-width:500px;
}

.game-entry img {
    width:100%;
    position:relative;
}

.game-entry:hover .game-thumbnail {
        margin-top:-30%;
        padding-bottom:15%;
        bottom:0;
}
.game-entry:hover .moreinfo {
        opacity:1;
        transition:opacity ease-out;
        transition-duration: 0.4s;
        transition-delay: 0.3s;
}

.moreinfo {
    opacity:0;
    transition-duration: 0.2s;
    transition-delay: 0s;
    background-color:#171e1a;
    width:25%;
    padding:5px;
    text-align:center;
    position:relative;
    float:right;
}
<div class="container-fluid my-0 px-5 py-1">
    <div class="container-fluid p-2 d-none d-md-block">
        <div class="row">
            <div class="col-sm-auto p-2">
                <div class="container-fluid p-0 m-0 game-entry">
                    <img src="https://i.imgur.com/cxLk553.png">
                    <div class="container-fluid game-thumbnail">
                        <h4>My Dog's Tale</h4>
                        <p>Follow the adventures of My Dog</p>
                        <div class="moreinfo">More info...</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <h1 class="my-4" style="color:black;">This should not go up</h1>

I'm contemplating adjusting the positioning of the text upwards and increasing the size of the div at the top, but I'm encountering issues with the background getting obscured by the image.

While I prefer a CSS3-only solution, I am open to suggestions that involve jQuery as well.

Answer №1

When adjusting the positioning of an element using margin, it can disrupt the overall DOM flow of the page, leading to unexpected impacts on elements below.

To avoid this issue, I suggest utilizing the transform property for animations instead. For instance, you can use transform: translateY(-30%); to smoothly move the element without affecting the DOM flow.

Feel free to check out the revised fiddle here.

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 Clojure Hiccup for crafting stylish information in a unique manner

I want to create CSS style using hiccup by specifying the "top" and "left" variables to position an element. Currently, my code looks like this: (html [:div {:style (str "top" top ";left" left)} "some text"]) The code above is not very clean. It ...

When using JavaScript, links within the window.location are automatically altered

When using window.location (.assign, .replace, .href) to redirect to a product page on click, I encountered an issue where it automatically changes some of the href links. For example: instead of "previous href= 'commercial/fonts/fonts.min.css' ...

Is an Object in Javascript an Array of Elements?

Today, I am facing a challenge. I have an HTML Form that can contain a variable number of HTML Input Fields for email addresses. I am using Javascript to process this data and to post it via XMLHttpRequest. To fetch the input fields, I use the following c ...

Moving smoothly while retaining absolute positioning

I have a question about a particular scenario. I have a div element that is styled like a ball and I want it to transition diagonally across the page to the bottom right corner instead of moving suddenly. However, this is not happening as expected. Can you ...

Inquiring about how to make the pieces move on the checker boards I created

I'm having trouble getting my SVG pieces to move on the checkerboard. Can someone please help me figure out how to make them move, even if it's not a valid move? I just want to see them in motion! The important thing is that the pieces stay withi ...

Leveraging .Net ConfigurationManager.AppSettings in Cascading Style Sheets

I am facing an issue where I have a specific color key in my AppSettings for the company's brand color, which needs to be applied to a CSS class. The challenge is how to incorporate this key into my stylesheet. Is there a way to access the Configurati ...

How can I ensure text remains confined within the parent div when working with Bootstrap?

I'm having trouble keeping the text and links within their parent div. Even though I set the outer boundary as col-sm-8, the text and links are overflowing. I'm not sure what I'm doing wrong, but the code I am using is shown below. I have a ...

Converting HTML tables into R

I have a series of HTML files with static content containing tables. I need to extract a specific column (4th column) from each table. I am currently using R to extract the tables from the HTML, but it seems like the rows are being combined for that partic ...

Tips on improving a function that verifies the existence of an image used as a CSS background to output a boolean value

I have encountered a challenge while working on a react file-upload component. The issue at hand is relatively simple - I aim to display an icon corresponding to the file extension for each uploaded file. These icons are loaded through css as background im ...

Is there a way to position an X item on the first row and another X item on the following row using flexbox?

I want to use flexbox to arrange 10 buttons in a row on a large screen. On a medium screen, I'd like 5 buttons on the first row and 5 on the second row. For small screens, 2 buttons per row, and for very small screens, one button per row. It's im ...

Change the JavaFX ToggleButton's color and revert back to its original color

Can you tell me what the default background and border color is for a toggle button? Here’s an example of code that changes the background color of a toggle button: i.toggle11.setOnAction(e->{ if(i.toggle11.isSelected()){ i.toggle ...

Rendering Local HTML with local styling and scripts in React Native Webview

I am having trouble loading a local HTML, CSS, and JS file in my React Native webview. The CSS is not being applied to the HTML. Here is my folder structure: https://i.sstatic.net/mqYT9.png My HTML file, along with CSS, images, and JS file are all placed ...

Get your columns in order with Bootstrap4

I need to rearrange my 3 columns on desktop and mobile devices in different ways. Currently, my grid structure is set up like this: <div class="row"> <div class="col-xs-3 col-md-6"> 1 </div> <div class="col-xs-3 col-md- ...

Steps to trigger a Bootstrap modal when the user clicks anywhere on the webpage

I need assistance with setting up a Bootstrap dialogue modal to open at the clicked position on a mousedown event when a user interacts with the page. Despite my attempts, the dialogue modal is not opening where it should be. Here's what I've tri ...

What steps do I need to take to get the Bootstrap dropdown menu functioning

I have an Angular app and have copied the Navbar from the Bootstrap script, pasting it under a menu component. The Navbar works fine, but the drop-down menu doesn't seem to be working. I am wondering how I can make this function properly. I have also ...

Populate any void area when <td> is not occupied in <tr>

I have a table with two rows and columns. If one of the columns is empty, it should move up to the upper row. For example: |td1 | td2| |td3 | | |td5 | td6| This is what I want: |td1 | td2| |td3 | td5| |td6 | | Below is the code snippet that ...

Can you explain the significance of xs, md, and lg within the CSS Flexbox framework?

Currently in the process of developing an application using React and looking to apply some styles to my components. I stumbled upon which delves into a fluid grid system. A snippet from the example is shown below: <Row> <Col xs={12} sm={3} m ...

Choose Option 1 in order to proceed with selecting Option 2 and displaying the outcome in the VueJs framework

Looking for help on how to show the text value from multiple related select fields. I want Option 1 to display a list of parent options. Upon selecting an Option 1, it should determine what values are available in Option 2 select field. After selection, ...

I'm encountering an issue where it appears that my ajax method may not be effectively communicating with my webservice

I am currently working on calling a webservice using an ajax request with the intention of retrieving clinical cases within a specific date range (for example, between 2015-01-01 and 2016-06-08). The webservice functions perfectly when tested individually. ...

Does the physical size of the CSS pixel unit change when the screen pixel density changes?

My current focus is on understanding responsive images, particularly in relation to setting image dimensions. For instance, if I were to set an image with a width of 100px and height of 100px, would it appear smaller on a high-resolution screen? I am cur ...