Adjusting the bottom property to a negative value in CSS will stretch the page downwards

I want to hide a portion of an HTML element at the bottom of the page and then reveal the entire element by sliding it upwards upon clicking with the help of CSS3 transitions.

The expected behavior is for the part of the element extending below the page to be hidden. However, the current issue is that the page is being extended to display that part of the element.

How can I resolve this problem?

Below is my code snippet:

HTML:

<div class="closed" id="slidePanel">
    <div id="slidePanel-tab">
            Stuff
    </div>
    <div id="slidePanel-contents">
        <ol>
            <li>stuff</li>
            <li>stuff</li>
        </ol>
    </div>
</div>

CSS:

#slidePanel {
    background-color: #e9e9e9;
    position: absolute;
    bottom: 0;
    left: calc(50% - 66px);   
    z-index: 2;
    min-width: 10%;
    min-height: 20%;
    border: 2px solid rgba(0, 0, 0, .05);

    -webkit-transition: bottom 0.5s ease-in-out;
    transition: bottom 0.5s ease-in-out;
}

#slidePanel.closed {
    bottom: calc(-20% + 20px);

    -webkit-transition: bottom 0.5s ease-in-out;
    transition: bottom 0.5s ease-in-out;
}

#slidePanel-tab {
    background-color: #d0d0d0;
}

$("#slidePanel-tab").click(function (evt) {
    $("#slidePanel").toggleClass("closed");

    evt.preventDefault();
});

Example: https://jsfiddle.net/sd306pyr/

Answer №1

To keep the element in place, you can define its position as fixed:

#slidePanel {
background-color: #e9e9e9;
position: fixed;
bottom: 0;
left: calc(50% - 66px);   
z-index: 2;
min-width: 10%;/*30%; */
min-height: 20%;
border: 2px solid rgba(0, 0, 0, .05); 
-webkit-transition: bottom 0.5s ease-in-out;
transition: bottom 0.5s ease-in-out;
}

Check out the fiddle: https://jsfiddle.net/sd306pyr/2/

You may also opt to set the overflow property of the element's container to hidden as suggested in the responses to your inquiry. Choose the approach that complements the overall layout of your DOM better.

Answer №2

For optimal performance, it is recommended to create a JavaScript script that adjusts the display property to none once the transition has been completed. Additionally, setting the overflow property of the body to hidden can help improve user experience.

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

What are some methods for toggling text visibility in PHP?

I am facing confusion regarding the functionality of this code. Here is the snippet in question : //start date to end date <?php if($show5 < $show6) { ?> <a>show content</a> <?php }?> If both 'start da ...

What is the best way to make a span's background color stretch to 100% width?

Is there a way to make the background of a span element stretch to the full width of its parent container? Just to Clarify I understand that using divs is an option, but it feels more like a workaround than a genuine solution to the issue. (di ...

Loading images lazily using knockout.js

I have been working on implementing lazy loading for images using knockoutjs binding. I previously successfully implemented lazy loading without the knockoutjs framework, but I am unsure of how to achieve this with knockoutjs binding. Below is my HTML code ...

Securing your Node.js connect-rest REST API with OAuth: A comprehensive guide

After conducting an extensive search on Google for examples related to my query, I was left empty-handed due to the generic name of the "connect-rest" package. My objective is to secure a server side API that I have built using the Node module "connect-re ...

Changing Marker Color in Google Maps API

There are multiple Google Maps Markers colors based on certain conditions being TRUE or not. In addition, these Markers will change color when the mouse hovers over a division (a1,a2..ax). I want the Markers to revert back to their original color when th ...

Tabulator - Using AJAX to retrieve a JSON document

I am currently working on importing a json file from an Azure blob container using Azure Data Factory. Despite closely following the documentation and researching various resources on Stack Overflow, I am facing challenges with making the ajax request fun ...

Tag in HTML not being replaced

Within my HTML snippet, I have encountered some <br> tags <div id="reading-project"> <p>The next morning, as soon as the sun was up, they started on their way, and soon saw a beautiful green glow in the sky just before them."That must b ...

Letters are frolicking in varying sizes and designs

Currently, I am encountering a strange issue with the text on my webpage. Some fonts are displaying with completely different shapes and sizes despite using <meta charset="UTF-8"> to ensure font consistency. Unfortunately, this did not resolve the pr ...

The icons from Font Awesome are not displaying properly in Angular version 15

I have been searching for new information to help solve the error I am experiencing but haven't found any useful results. Here is my issue: I am working on a project in Angular 15.1.0 and want to incorporate some Font Awesome icons. To do this, I foll ...

Shooting star css animation featuring pre and post effects

Trying to create a falling star using CSS animation. I made a star with a pseudo element, but I'm having trouble setting the animation in the pseudo-element. i{ position: relative; width: 0; height: 0; border-left: 12px solid transpa ...

Methods for decoding a JSON object and iterating through its contents

After learning how to encode an object on the server side from this post, I am now interested in decoding it on the client side. Following is what I do on the client side: $.ajax({ type: "GET", url: "/cgi-bin/ajax_sort.pl", contentType: "appl ...

I’m keen on utilizing JQuery with Node.js and EJS, but I’m encountering an issue where $ is not

I attempted to incorporate JQuery in my project by following these steps. Installed jquery using npm install Modified the package.json file Despite this, the functionality still does not work as intended. Below is a snippet of the .ejs page: <html& ...

The term "landscape" to address the issue of adjusting the Android app screen to display in landscape orientation is not being acknowledged

I am working on an Android app using HTML5 and Cordova. I've included the following code in the manifest.json file as a reference. However, I'm facing an issue where the app screen does not stay fixed horizontally. It only turns sideways when th ...

jsp fullcalendar select not functioning properly

The code snippet for the select: function within fullcalendar is as follows: select: function(start, end, jsEvent, view) { if (start.isBefore(moment())) { $('#calendar').fullCalendar('unselect'); return false; } else { //ajax Cal ...

What steps should I follow to obtain the return value after invoking these functions?

I have a task that requires creating a nodejs script for two specific functions: Retrieve my public IP address. Update my public IP address on my freenom.com account for a registered domain. Currently, I have two separate scripts in place to accompl ...

Troubleshoot: Why is the Chrome Extension content script failing to prepend to the body

Currently, I am developing a content script for a Google Chrome browser extension that inserts a horizontal bar at the top of any webpage visited by the user. The issue arises when visiting google.com as Google's navigation bar covers my bar. Here is ...

Modifying JQuery function to target two IDs instead of just one

I am utilizing a bootstrap 5 tablist on my website that allows for navigating between tabs using custom left and right arrows. If I wish to introduce a second bootstrap 5 tablist with a new unique ID, how can I modify the code to integrate the new ID and e ...

What is the process for triggering an unordered list when I click on a table data cell within the Hospitals category?

Hi there! I need help with writing a JavaScript function for Hospitals in the code below. When I click on Hospitals, I want to display the values in the unordered list. Expected output: Hospitals--->onclick Bangalore| salem |Goa| Mangalore| Visakhapat ...

Tips for organizing user information to generate a pie chart

My goal is to dynamically collect user input data from form input textboxes to create a pie chart when the submit button is clicked. Currently, I have a test version set up with fixed values displayed here: <form style="margin-bottom: 50px;"> 1 val ...

Are there specific mappings for system colors in CSS across various browsers and operating systems?

The CSS specification outlines a variety of built-in system colors that can be utilized, such as Highlight and Background. Is there a correlation between these built-ins and the settings of different OS/Browsers? For instance, if I implement color: Highl ...