creating empty space below by expanding upwards

I have implemented some jQuery to make my div expand vertically, but it is causing a space below the div of equal height. I need this extra space removed.

The specific div in question is the one connected to the footer and contains the content "ABOUT PENDLEY MANOR." If there is a way to revert the div back to its original size before expanding, that would be greatly appreciated.

Check out the live URL:

Here is the HTML code:

<div class="index-about-expandable" id="index-about-expand-container">
            <h2>ABOUT PENDLEY MANOR</h2> <a><i class="fa fa-plus index-expand-plus" id="expand"></i></a>
            <div class="clearboth"></div>
            <p>this is a test</p>
        </div>

This is the jQuery script being used:

<script type="text/javascript>
            $(function() {
                $("#expand").click(function() {
                    $("#index-about-expand-container").animate({'height': '270px', 'top': "-220px"});
                });
            });
        </script>

And here is the corresponding CSS:

#index .index-about-expandable { background-color: #433131; padding: 1px 10px; color: #fff; width: 240px; margin-top: 27px; position: relative; z-index: 5; overflow: hidden; height: 45px; }
#index .index-about-expandable i { font-size: 14px; float: left; margin-top: 15px; }
#index .index-about-expandable h2 { float: left; margin-right: 20px; }

Answer №1

This issue is often caused by using relative positioning, which can be quite troublesome to deal with. I usually find it best to steer clear of this method.

One solution could be to move the div#expand into the footer section. If the footer does not have a relative position, then you may need to surround #expand with a container that has a relative position instead.

Next, you can set the position of #expand as absolute and give it a negative Top property value that suits your needs.

When it comes to your javascript, make sure to adjust the top property accordingly when you change the height of the element.

Hope this helps!

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

Creating a toggle button for a div element to expand and collapse its content: Step-by-step guide

For my e-commerce site selling musical instruments, I'm designing a product landing page that showcases guitars, keyboards, violins, and cellos. As part of the design, I want to include expandable sections with detailed information about each instrume ...

Check to see if the cursor is positioned on the newly created raphael element without requiring a new mouse

After creating a new element using Raphael.js, I have noticed that hover events do not trigger on Chrome (42.0.2311.90) or Internet Explorer (11.0.8) when the element is under an idle cursor. However, Firefox (31.0, 32.0.2, and 37.0.2) works as intended. ...

I'm confused as to why the CSS Bottom property is causing the top edge of the div to align with the bottom of the document rather than the bottom edge

My challenge is to align an image slideshow on top of my footer, with the bottom edge of the slider touching the top edge of the footer. Despite using position: fixed and bottom: 0 properties, it appears that the positioning is off - aligning the top edge ...

Aligning columns vertically in the Bootstrap grid

So you've got a layout with two columns using Twitter Bootstrap, and you want to make sure specific rows are vertically aligned: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/css/bootstrap.min.css"/> < ...

I'm curious as to why these two divs are positioned side by side. Can anyone shed some light on why this footer isn't functioning properly

My goal is to showcase the logo along with 3 buttons containing all the social media links underneath it. However, for some reason, my 2 divs are displaying inline instead of flex or block. Can anyone shed light on why this isn't functioning as expect ...

Using JQuery to find the nearest element and narrowing down the search to its child elements

In my program, I have 3 forms identified by form1, form2, and form3. Each form contains its own set of dropdown lists named drop1 and drop2, along with a submit button. When the submit button is clicked in any form, it checks which option was selected from ...

"Exploring the wonders of a jQuery plugin within the

Can anyone recommend a plugin for eclipse Luna that offers complete jQuery functionality? I've noticed that JSDT doesn't provide all the features. Thank you! ...

React Native: The behavior of the 'top' property is consistent, while the 'bottom' property is not performing as anticipated

Within my React Native application, I have implemented the following code: <View style={{ width: 50, height: 50, borderWidth: 1, }} > <View style={{ width: 5, height: 5, backgroundColor: 'red', top: 10, ...

Conceal and unveil stationary navigation when scrolling back to the very top of the screen

My current setup includes a navigation that dynamically hides as the user scrolls down and reappears when scrolling up. Additionally, I have applied the class .fixed on #top-wrapper to alter the layout/styling of this specific div. However, I am facing dif ...

Using Jquery to automatically assign dynamic class names to a table with incremental values

I'm working with a table and here is the current code snippet: <table> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> & ...

Incorporate a button within a listview on Kendoui to trigger the opening of a modal window

I am seeking assistance on how to insert a button on each element of a Listview (PHP/Json) result. When clicked, this button should open a modal window where the customer can input reservation details such as Date, Adults, and Children. Below is the JavaSc ...

Ways to conceal elements when a webpage is displayed in a pop-up window

JavaScript // Open popup window $('a.popup').click(function(){ window.open( this.href, 'Page title', 'width=600, height=650' ); return false; }); HTML snippet <a class="popup" href="sample.html"> In order to ...

Issue with jQuery ajax and servlet communication

Hey there, I've been working with servlet, JSP, jQuery, and AJAX in my project. I've implemented AJAX to retrieve data from the name column in an Oracle database for auto complete functionality. Everything seems to be working fine initially, but ...

Conflicting jQuery plugins - issues with using .load and hover intent together

I am attempting to integrate these two separate scripts into one website. Here is the code for each: <script type="text/javascript"> $(document).ready(function() { var name = ""; $(".home-roll-box").hover(function() { n ...

The quantity addition and subtraction function is malfunctioning

I have implemented a quantity plus/minus feature in HTML which is embedded from a jQuery script provided below. jQuery.ajax({ type: "POST", url: "http://ayambrand-com-my-v1.cloudaccess.host/index.php?option=com_echa ...

Switch up the appearance of a document by manipulating the stylesheet using a select tag

I'm currently facing an issue with the implementation of a drop-down box on my website for selecting different themes. Despite having the necessary javascript code, I am unable to get it working correctly. Here's the snippet: //selecting the sele ...

When conditions are met, all items are added to the array

In my Angular app, I have a user list that I am trying to filter based on the condition age > 45. However, all users are being pushed into the validForScheme array instead of just those meeting the condition. I am unable to figure out what is going wron ...

Rearrange lists by dragging and dropping them according to specific criteria

In my AngularJS project, I am utilizing the angular-drag-and-drop-lists library from here to create two lists with the following functionalities: Dragging items from list A to list B Dragging items from list B to list A Reordering items in list A Reorder ...

The Empty Spaces Surrounding the Navigation Bar in HTML/CSS

I am just starting out with CSS and HTML. Is there a way to eliminate the gaps around my navigation bar? Here is an example image showing the gaps around the navbar. I have attempted using width and height attributes but it did not resolve the issue. ...

Struggling with uploading files in AngularJS?

Below is the code snippet from my controller file where I aim to retrieve the values of various input elements (name, price, date, image) and store them in an array of objects... $scope.addBook = function(name, price, date, image) { name = $scope ...