Switching from a top to bottom position can be quite the challenge for many

If there's a more efficient method for accomplishing what I'm about to inquire about, please inform me. So far, this is the best solution I could devise.

I am looking to have a series of divs that enclose a sliding div within them. The sliding divs will feature content extracted from the most recent post, potentially resulting in varying heights.

The initial display should show the title only and reveal the entire div upon hovering over the parent element.

Using only the bottom position poses an issue when the screen width becomes too narrow as more than just the title becomes visible. Although utilizing the top position sacrifices some of the title display, I am willing to compromise on that front.

To address this challenge, I opted to incorporate both top and bottom positions, toggling the placement of 'auto' to reveal the complete div. I do not want the sliding div to match the height of the container div.

However, integrating these changes seems to hinder the transition effect. I attempted incorporating top, bottom, and all in the transitions, yet encountered the same lack of transition effect.

Could someone kindly clarify a) why this approach is ineffective b) provide alternative solutions without resorting to jQuery?

HTML:

<div class="innerLeftPosts">
    <div class="mainPostHome">
        <div class="postSlideCover">
            <h3>Hello this is a test</h3>
            <p>This is some test content that would go in here and take up some space</p>
        </div>
    </div>
    <div class="secondaryPostHome">
        <div class="postSlideCover">
            <h3>Hello this is a test</h3>
            <p>This is some test content that would go in here and take up some space</p>
        </div>
    </div>
</div>

CSS:

.postSlideCover{
width:calc(100% - 20px);
height:auto;
position:absolute;
    transition:all 0.4s ease-out;
    -webkit-transition:all 0.4s ease-out;
}
.mainPostHome .postSlideCover{
    top:83%;
    bottom:auto;
}

.mainPostHome:hover .postSlideCover{
    top:auto;
    bottom:0;
}

Fiddle for full and visual example: https://jsfiddle.net/60nxpfs8/

Answer №1

Here's the code snippet:

.postSlideCover{
    width:calc(100% - 20px);
    height:auto;
    position:absolute;
    transition:all 0.4s ease-out;
    -webkit-transition:all 0.4s ease-out;
    bottom: 0;
}
.mainPostHome .postSlideCover{
    transform: translateY(60%);
}

.mainPostHome:hover .postSlideCover{
    transform: translateY(0);
}

Check out this JSFiddle link

This CSS utilizes the translateY property with the transform property to move an element based on its own height (100% represents the full height of the element). By using hardware acceleration, we can achieve smoother animations.

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

Is it possible to apply border-radius to selections, similar to how it is done in vscode

It was reminiscent of this... Visual Studio Code ::selection{ border-radius: 5px; } I attempted something similar to this, however it was not successful... ...

What is the solution for adjusting the positioning of the `<select>` element in Bootstrap?

Here is a snippet of HTML code: <button class="btn">hello</button> <select class="input-small"><option>1</option></select> <button class="btn">world</button> The position of the select element is not correc ...

Strategies for styling the contents within <details> while excluding <summary> in CSS

I'm attempting to apply a 10px padding to the Story box using CSS, without introducing any additional HTML elements into the website code. Is there a way to include the padding in the Story box without incorporating a new HTML element? To clarify: H ...

The table headers in the second table do not match the queryAllSelector

I've encountered an issue with my JavaScript snippet that displays a responsive table. When I use the snippet for a second table with the same class, the formatting gets messed up on mobile devices (try resizing your screen to see). It seems like the ...

What is the best method to retrieve child elements from a class list object?

Seems like I have a similar content class <div class="parentclass"> <div class="childClass"> </div> <div class="childClass"> </div> <div class="childClass"> </d ...

Ways to assign a CSS class specifically for images

.calendarList { background-image: url('/resource3/hpsc/common/images/calendar.png'); background-position: 135px 50%; background-repeat: no-repeat; cursor:pointer; } <input type="text" id="toDatepicker" class="cal ...

The MUI makeStyles() class has been implemented, yet the styles are not being displayed when using classList.add('class-name')

Currently, I am utilizing MUI makeStyles() to create a series of CSS classes. Within these classes, I am dynamically including and excluding one specific class to my Box element during file drag-and-drop events. The class is successfully added, as I can o ...

Float from the bottom and then rise up

I'm attempting to use CSS to make code from further down in the HTML appear above code from a section above it. Here is how my HTML structure looks: <div class="showbelow"> show below </div> <div class="showabove"> show above < ...

Glowing semi-opaque about spotify?

Recently, I decided to challenge myself by recreating the Spotify homepage using only pure Javascript and SCSS as a way to test my front-end development skills. You can view my progress so far at this link, although please note that it's still a work ...

Adjusting the layering of a nested element within a container div using

I am facing an issue with two buttons placed within a container div that is being overlapped by another container div. The bottom container overlaps the top one, rendering the buttons unclickable. I have been trying to find a solution to make the buttons ...

Place a <ul> list in the center

I've hit a roadblock trying to find a solution for this issue. Nothing I've attempted so far has proven successful. I'm hopeful that someone could lend me a hand. The challenge at hand involves centering a standard <ul> list on the pa ...

Using Slick Slider and Bootstrap CSS to display text on top of images

Currently, I am utilizing the slick slider from and I want to overlay text on top of the image. I tried using bootstrap carousel-caption, which works well with any image. However, with slick slider, it seems like the text is not at the highest level as I ...

Content is not centered with Bootstrap's flexbox

The alignment of content is not centered using bootstrap flex <div class="d-flex flex-row bd-highlight mb-3"> <div class="p-2 bd-highlight text-left"><i class="fa fa-chevron-left" aria-hidden="true"></i></div> <div cla ...

Displaying elements above my React sidebar

I am working on developing a Login application with a landing page using React Router and Redux. In order to have a Sidebar that is always present in all the components within the application, I have setup the Sidebar component as a route that is constantl ...

Arranging Images with CSS Overlapping

I am striving to make the blue block and red block scale proportionally with the webpage, while also maintaining their position without any shifting up or down. As depicted in this gif, the blocks somewhat accomplish what I desire when scaling diagonally, ...

Arrange three div elements to create a layout that is optimized for different screen sizes

Is there a way to align these 3 divs as follows: pickup on the left, phone in the middle, and delivery on the right? I've browsed through similar alignment issues on Stack Overflow, but none of the solutions seem to work for my specific code. It' ...

Difficulty adjusting image size in "layouts with overflowing images on cards."

I have encountered an issue with resizing images on my browser using a card-based layout that I found on codepen. The strange thing is, the image resizing works perfectly fine on codepen itself, but when I try to implement the same HTML and stylesheet on m ...

Gallery tiled with images enclosed in <a> tags

I've been experimenting with pure CSS (Bootstrap 4) to create a tiled gallery layout. To achieve this, I've been utilizing the flexbox capabilities provided by Bootstrap through classes like d-flex and flex-wrap. While everything seems to be wor ...

Alignment of menu blocks

I'm struggling to line up all the menu items at the bottom - products, activity feed, and learn store should be on the same row, with test below products. Currently, products is being pushed up and text is aligning to the right of it. Despite trying ...

"Troubleshooting a dropdown navigation bar problem in CSS

I am currently working on creating a CSS navbar dropdown, but I am encountering some issues. I am not very experienced with CSS, so any assistance would be greatly appreciated. The text within the "Products" box is not changing color like it should, and yo ...