Guidelines for positioning an object to float in the bottom right of a separate tag

I am trying to position an image at the bottom right of a parent div.

The CSS solution I found from another answer did not work as expected, so I had to use JavaScript to achieve the desired result. Is there a way to do this without using JavaScript?

(Please note that the code provided may not work in online editors like jsfiddle or cssdesk.com)

<style>
    .container {
        overflow: auto;
        background-color: green;
    }

    img {
        height: 200px;
        width: 150px;
        background-color: white;
        border: 50px double steelblue;
        box-sizing: border-box;
        float: right;
        clear: right;
    }

    .spacer {
        /* height: calc(100% - 200px); <--- this one sadly doesn't work */
        float: right;
    }
</style>
<div style="background-color: blue">header + other stuff</div>
<div class="container" id="container">
    <div class="spacer" id="spacer"></div>
    <img id="img" />
    <p>
        Conceptualizing random endpoints in an access matrix 
        provides reach extensions enterprise wide. Respective 
        divisions historically insignificant, upscale trendlines 
        in a management inventory analysis survivability format.
    </p><p>
        Document-centric projections unfetter traditional 
        auditing practices rivaling central process management. 
        Advanced functionality, easy administration, proclaim 
        the hallmarks of unprecedented opportunity.
    </p><p>
        Iteration system-wide engenders economies of scale, 
        cross-media technology, presentation action items and 
        life cycle replication.
    </p><p>
        Enterprise engenderment accelerates initiative platforms, 
        reducing staffing components, integration of technical 
        accessibility, resulting in bottom line pluralisms, 
        benefit-wise. Incidental re-sizing staff requirements 
        through attrition can be accelerated by paradigm shifts 
        and focusing on core suitability and cross-training.
    </p><p>
        Marketing teams input produce cross purposing in view of 
        goal alignments due to knowledge paucity, necessitating 
        workflow education and orientation. Media sourcing as an 
        acquisition strategy is counterproductive in a internet 
        environment in virtual component methodology. Imaging 
        through ideals rather than real world branding, is a 
        perilous undertaking with negative results. Branding 
        strategies generating motion as activity without 
        reproducible results is a ultimately futile effort if 
        left in place.
    </p><p>
        Analysis of funding is inappropriate in this effort as 
        assets are repurposed in statements who existence owe 
        their identity to their obscurity. Obfuscation of 
        responsibility underlines these offerings, whose primary 
        function is to generate revenue and secondarily to shift 
        accountability downstream.
    </p><p>
        Syntactically valid structuring implementation, 
        enhancement based reporting, technology development, 
        proprietary incidentals administration are all areas of 
        content modularization engaging visibility deficits. 
        Cyberliability management procedures underlining 
        performance degradation vouchsafing interdepartmental 
        communication guideline infrastructure for evaluating 
        content management.
    </p>
</div>
<div style="background-color: red">other stuff + footer</div>

Answer №1

Using JavaScript, a clever solution involves leveraging the browser's ability to update the container's height and using that information to adjust the image's position.

The yellow box displayed below should ideally have a width of 0px in order to accurately depict what is happening without any visual clutter. However, for demonstration purposes, it has been widened to show debug output from the JavaScript code.

<style>
    .spacer {
        width: 150px;
        background-color: yellow;
    }
</style>
<script>
(function() {
    document.addEventListener("DOMContentLoaded", 
    function (e) {
        var container = document.getElementById("container");
        var spacer    = document.getElementById("spacer");
        var img       = document.getElementById("img");

        var c_container = window.getComputedStyle(container);
        var c_img       = window.getComputedStyle(img      );

        var prev_width = 0;

        setInterval(
            function() {
                if (!document.hidden) {
                    var w_container = parseInt(c_container.getPropertyValue("width"));

                    var h_img       = parseInt(c_img      .getPropertyValue("height"));
                    if (w_container > prev_width) {
                        var h_container = h_img;
                    } else {
                        var h_container = parseInt(c_container.getPropertyValue("height"));
                    }
                    prev_width = w_container;
                    var h_spacer    = h_container - h_img;

                    spacer.style.height = h_spacer;

                    spacer.innerHTML = ""
                        + "w_container: " + w_container + "</br>"
                        + "prev_width: " + prev_width + "</br>"
                        + "h_container: " + h_container + "</br>"
                        + "h_img: " + h_img+ "</br>"
                        + "h_spacer: " + h_spacer + "</br>"
                    ;
                }
            }, 100
        );
    }
    );
})();
</script>

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

Ensuring Form Validation in Symfony 2.0 View

I am currently using Symfony 2.0 and I have a view file called test.html.php which includes a form: <form action="" method="post" rel=""> <input type="hidden" name="action" value="test" /> <input name="myinput" type="text" value="" ...

ReactJS - Travel Booking Platform with Advanced Date and Price Filtering

Currently, I am in the process of developing a project — a website similar to AirBnB or Booking.com for booking rooms. The backend is built on Java Spring, while the frontend uses ReactJs. Although most of the code runs smoothly, I'm encountering s ...

How do I set up a timing mechanism in a VSCode extension to automatically clear error messages after a specified duration?

I'm currently in the process of developing a VSCode extension, and ran into an issue where I need to display an error message if a certain condition is met. However, I want this error message to automatically disappear after a set amount of time (say, ...

Eliminating the standard padding on a Vuetify v-app-bar

When using Vuetify's v-app-bar, there are default css classes named v-toolbar__content and v-toolbar__extension that apply padding of 16px on the x-axis and 4px on the y-axis, which I aim to eliminate. I attempted to override these classes in my CSS ...

Introduce a pause interval between successive ajax get calls

I've created a script that uses an ajax GET request when the user reaches near the end of the page. $(function(){ window.addEventListener('scroll', fetchImages); window.addEventListener('scroll', fetchNotifications); }); ...

click events in backbone not triggering as expected

It's puzzling to me why this is happening. The situation seems very out of the ordinary. Typically, when I want an action to be triggered on a button click, I would use the following code snippet: events:{ 'click #button_name':'somefun ...

The eel feature results in no output

During my Python program development using the Eel module, I encountered an issue. The problem is that the eel.getImgSrc(path) function returns null when trying to retrieve image's byte data. Take a look at this example: -----web/main.js------ async ...

What are the reasons behind the inability to import an image file in Next.js?

Having an issue with importing image file in Next.js I'm not sure why I can't import the image file... The image file is located at 'image/images.jpg' In Chrome browser, there are no error messages related to the image, However, in ...

The functionality of the submit form is encountering issues upon integration of Ajax requests

Hello everybody! I am currently creating a dynamic form for editing specific classes, but I am facing an issue with the ajax call not working. Below is the HTML code for the form: <form id="userDataForm" name="userDataForm" th:acti ...

Tips for restricting function invocations in JavaScript?

I am seeking a function called limitCalls(fn, maxCalls) which accepts a function fn and creates a new function that can only be called the specified number of times in maxCalls. Here is a test example: it('limitCalls', () => { const makeIncre ...

Guide for displaying a React Bootstrap modal within a function

Currently, I am integrating a React Bootstrap modal popup into my project. The goal is to have the modal display when a user submits a form. The specific modal component I am using is called SaveConfirmationModal. import { Button, Modal} from "react- ...

Exploring the wonders of Node.js, Redis, and Express.js while navigating through the enchanting world of Asynchronous

Hello there, I must confess that this is a whole new realm for me... Here is what we've got: app.get('/user/:user_id/followings', function(req, res) { var response = {} , userId = req.params.user_id , ids = req.param(' ...

Updates made in MobX store are not displaying in the web browser

Why are the data changes not reflecting in the view after the api call? Here is the code snippet that might help: store.js import axios from 'axios'; import {encrypt, decrypt} from '../utils/pgp.js' import {observable, action, compute ...

After clicking the submit button, make sure to automatically fill in all empty input fields

I am currently working on a form that includes various input types such as text fields, radio buttons, select dropdowns, and text areas. The form is displayed in a table format with an option to add additional rows. One issue I have encountered is that us ...

Tips for acquiring the newest router in an angular environment

Is there a way to retrieve and store the URL of the latest router that the user has visited in local storage? Any suggestions would be greatly appreciated. Thank you! ...

Error message displayed: MUI Textfield does not support input of decimal values

I have a textfield where users can enter the unit price const [unitPrice, setUnitPrice] = useState(0); <TextField label="Unit Price" variant="outlined" margin="normal" value={unitPrice.toString ...

Grab a parameter from the URL and insert it into an element before smoothly scrolling down to that

On a button, I have a URL that looks like this: www.mywebsite.com/infopage?scrollTo=section-header&#tab3 After clicking the button, it takes me to the URL above and opens up the tab labeled tab3, just as expected. However, I would like it to direct m ...

The issue of Access-Control-Allow-Origin not functioning properly when using Ajax for a POST request

I am encountering an issue with the header "Access-control-allow-origin" when making a request using the following code: <script type='text/javascript'> function save() { $.ajax( { type: 'POST', ur ...

Understanding the request URL in Ajax when receiving a response

How can the URL of a jQuery request be retrieved from the response received? Perhaps something like this: function retrieveUrlFromResponse(response, url){ requestUrl = url; } ...

I noticed an excess of white space on the right side of my Angular website

Check out my website here. Everything seems to be functioning correctly, however, there is an issue with scrolling on mobile. It should only scroll up and down, not left and right! I have noticed a strange white space on the right side of my site when view ...