Adjust the placement of a div element

This snippet shows the CSS styles being used:

<style type="text/css">
#search_results{position:relative;height:369px;overflow:auto}
#floating{background-color:#eee;padding:15px;position:absolute;bottom:0px}
</style>

I am facing an issue with positioning the floating div at the bottom of the search results div. When I apply the above CSS to the floating div, it sticks to the bottom as expected and works fine when scrolling the window. However, the problem arises when scrolling inside the search_results div as the position of the floating div changes. I need the floating div to stay fixed at the bottom of the search results div regardless of whether the page or the search results div is scrolled. I tried a script which seems to work well in all browsers except IE, where there are some jerks. How can I fix this so that the div stays at the bottom at all times?

<div style="width:695px;border:1px solid red" id="search_results">
    <div id="floating">test block</div>
       <div style="padding:25px 0;border-bottom:1px solid green">       
          <div style="float:left">
            <p>test1</p>
            <p class="mrgBtm5px">random no</p>
            <p>
                <span>lorem ipsum</span><br/>
                <span>lorem ipsum expand</span>

            </p>
          </div>         
            <div style="clear:both"></div>  
        </div> 
        <div style="padding:25px 0;border-bottom:1px solid green">      
          <div style="float:left">
            <p>test1</p>
            <p class="mrgBtm5px">random no</p>
            <p>
                <span>lorem ipsum</span><br/>
                <span>lorem ipsum expand</span>

            </p>
          </div>         
            <div style="clear:both"></div>  
        </div>
         <div style="padding:25px 0;border-bottom:1px solid green">     
          <div style="float:left">
            <p>test1</p>
            <p class="mrgBtm5px">random no</p>
            <p>
                <span>lorem ipsum</span><br/>
                <span>lorem ipsum expand</span>

            </p>
          </div>         
            <div style="clear:both"></div>  
        </div> 
</div>

Answer №1

To enhance the layout, relocate the floating div from the search div,

<div style="width:695px;border:1px solid red" id="search_results">

       <div style="padding:25px 0;border-bottom:1px solid green">       
          <div style="float:left">
            <p>test1</p>
            <p class="mrgBtm5px">random no</p>
            <p>
                <span>lorem ipsum</span><br/>
                <span>lorem ipsum expand</

               </p>
          </div>         
            <div style="clear:both"></div>  
        </div> 
        <div style="padding:25px 0;border-bottom:1px solid green">      
          <div style="float:left">
            <p>test1</p>
            <p class="mrgBtm5px">random no</p>
            <p>
                <span>lorem ipsum</span><br/>
               <span>lorem ipsum e/>

            </p>
          </div>         
            <div style="clear:both"></div>  
        </div>
         <div style="padding:25px 0;border-bottom:1px solid green">     
          <div style="float:left">
            <p>test1</p>
            <p class="mrgBtm5px">random no</p>
            <p>
                <span>lor/>

            </p>
          </div>         
            <div style="clear:both"></div>  
        </div> 
</div>
<div id="floating">test block</div>

Furthermore, implement the following CSS styles:

#floating {
    background-color: #EEEEEE;
    bottom: 0;
    display: inline-block;
    left: 1px;
    padding: 15px;
    position: relative;
    top: -51px;
}

View the result here: http://jsfiddle.net/6Qyvy/5/show

You can also add this CSS to the modified HTML above:

#floating {
    background-color: #EEEEEE;
    display: inline-block;
    margin-left: 1px;
   />

            

See the updated output: http://jsfiddle.net/6Qyvy/6/show/

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

Steps for designing a footer with a fixed width and transparent center gap that stays in place

Looking to create a fixed footer with a transparent gap at the center that is 100% fixed width? No scripts needed! EXPAND THIS WAY <<< ______ FIXED WIDTH GAP ______ >>> EXPAND THIS WAY MY OWN SOLUTION HTML <div id="Ftr"> ...

What's the best way to add row numbers within ajax requests?

I wrote a function that retrieves values from a form using jQuery's AJAX method: function getvalues(){ var sendid = $('#id').val(); $.ajax({ type: "POST", url: "ready.php", data: {sendid} }).done(function( result ) { $("#msg").html( "worked ...

Searching for a method to retrieve information from an API using jQuery in Node.js?

I'm currently working on fetching data from an api to display on the front-end. This is my server-side code - app.get('/chats',function(req,res){ User.find({}).exec(function(err,user){ res.send(user); }); }); On the clie ...

When scrolling, all sections display above the stationary header

On my home page, I have a header that remains fixed at the top of all sections. However, when I scroll down, the contents and sections appear above the fixed header, making it look like a background. Is there a way to ensure that all images and content go ...

Opacity of background color only applies to the color

So, here's the scenario - I currently have a background that looks like this: background:url(../img/arrow_lch.png) right no-repeat #2e443a; The challenge I'm facing is how to decrease the opacity of only the background color (#2e443a). Any sugg ...

How can I implement jQuery Ajax to handle multiple elements on a single webpage?

I recently created a page where users can add items to their "favorites" list using the following JavaScript code: $(function(){ $('.doit-01234').click(function (e) { e.preventDefault(); $.ajax({ url: "https://www.domain. ...

"Discover the method for successfully updating a linked dropdown menu when inputting new data in Yii2

I have added this code, but the dropdown to select subcategories does not work on the update page, it only works on the create page. How can I fix this? <?php $CoursesCat = ArrayHelper::map(CoursesCat::find()->all(),'id', 'cat_name&a ...

Ways to prevent styles from being overridden by those specified in JavaScript

Some elements on my page have their style dynamically changed by JavaScript. However, I want one of them to maintain its static style without being overridden. Is there a way to specify that the style of this particular element should not be altered? Than ...

iPhone 3GS and 4 not expanding DIVs by 100%

I've been encountering a significant issue with a div that's set to 100%. It displays properly on desktop screens, but on iPhones, there appears to be a gap on the right side. I've attempted to use the following CSS: body { min-width:980p ...

File transformation through CSS upon the addition of a new file

There is an issue with my files menubar.php and Homepage.php. When I include menubar.php in Homepage.php, it causes a change in the overall CSS of Homepage.php. The padding, margins, div height, and width all become scattered. I have attempted to troubles ...

Expanding the content width of Bootstrap Nav Pills

I'm currently working with Bootstrap pills that feature two tabs. I would like to customize the width of the tab content container differently for each tab, but I'm unsure how to achieve this. The tab-content class currently sets the same width f ...

What's the best way to ensure uniform card height in Material-UI?

Is there a way to ensure consistent card height in Material-UI without setting a fixed height? I want the card heights to dynamically adjust based on content, with all cards matching the tallest one on the website. How can this be achieved while also addin ...

Organizing data with Tablesorter and preserving the sorting order

My table contains valuable information that is initially generated from a PHP script and then updated every n-seconds by checking the database. To enhance the functionality of my table, I decided to install the tablesorter plugin. However, I encountered a ...

The art of website creation: incorporating images into the background and using image tracing techniques

Trying to figure out where to find a solution for this. I had the idea of using a semi-transparent Photoshop design as a background and building on top of it, almost like tracing over it. This way, aligning things would be much easier. I remember Microsoft ...

Issue with $.ajax() functionality persists across all browsers except for Firefox

Whenever the page loads, a small script I have retrieves rental dates. Additionally, if the user selects a different month from the drop down, new dates are also fetched. Unfortunately, the site is using jQuery 1.2.3 and I'm unable to update to 1.4 d ...

Organize images with overlays to the center of the page

I need help centering a group of pictures (a 3x3 table) on my webpage. I was able to center them before adding image overlays, but now the images are showing up in the top left corner of the page. How can I group and center them, and how do I specify the i ...

Struggling to extract information from a serialized Python object using JavaScript/jQuery?

Continuing the previous issue with an AJAX call to a Django view (restframework endpoint), the problem has now shifted to the frontend. $.ajax({ url: '/notify/', type:'GET', dataType: '', success: function (da ...

What is the solution to preventing contentEditable="true" from inserting <div> instead of <p> when the return key is pressed?

I have a div <div contentEditable="true"> <h1> My headline</h1> </div> When editing the text inside the <h1> tag and pressing return, a new div is added underneath instead of the usual paragraph tag. Resulting in: < ...

Retrieving JSON Arrays in PHP through an AJAX Request

Having trouble extracting data from multiple arrays in an AJAX request. Can anyone help? Here's what I'm trying to send: https://i.stack.imgur.com/4MEL4.png Executing a jQuery AJAX POST to a PHP file, but uncertain how to retrieve the data. An ...

VS Code warning about unused CSS selectors in SvelteKit

Is there a way to get rid of the Unused CSS selector warning in VS Code? I keep getting this warning in all files where I use <style lang="scss">. While I'm aware that I don't use the .btn class in some components, I still want it ...