Move the div to the bottom of its container

Is there a way to place a div at the bottom of its containing div?

<style>
.outside {
    width: 200px;
    height: 200px;
    background-color: #EEE; /*for visibility*/
}
.inside {
    position: absolute;
    bottom: 2px;
}
</style>
<div class="outside">
    <div class="inside">inside</div>
</div>

This code positions the text "inside" at the bottom of the container.

Answer №1

.container {
    width: 300px;
    height: 300px;
    background-color: #F4F4F4; /*for visibility*/
}

It is necessary to add

.container {
    position: relative;
    width: 300px;
    height: 300px;
    background-color: #F4F4F4; /*for visibility*/
}

Absolute positioning will search for the closest parent element with relative positioning in the document hierarchy. If none is found, it will default to using the body tag.

Answer №2

To achieve the desired layout, apply position:relative to the parent element with class .outside, and then add position:absolute; bottom:0; to the child element with class .inside.

Here's how you can do it:

.outside {
    position:relative;
}
.inside {
    position: absolute;
    bottom: 0;
}

Answer №3

Include position: relative in the style of .outer. (https://developer.mozilla.org/en-US/docs/CSS/position)

When an element is positioned relatively, it still maintains its position in the normal flow of elements within the document. On the other hand, absolutely positioned elements are removed from this flow and do not affect the positioning of other elements. An absolutely positioned element is placed relative to its closest ancestor that has a defined position. If no positioned ancestor exists, the initial container, known as <body>, is used.

By adding the suggested code, the .outer element becomes positioned accordingly.

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

Apply a see-through overlay onto the YouTube player and prevent the use of the right-click function

.wrapper-noaction { position: absolute; margin-top: -558px; width: 100%; height: 100%; border: 1px solid red; } .video-stat { width: 94%; margin: 0 auto; } .player-control { background: rgba(0, 0, 0, 0.8); border: 1px ...

Problem with Bootstrap slider animation

Currently, I am tackling a bootstrap slider project, where the images are all in place, and they transition every few seconds. Everything appears to be functioning correctly, except for the animation display. The image changes suddenly without any smooth t ...

Eliminate the standard cell padding in nested HTML tables

In my setup, there is a parent table where each td tag in the tr tag contains a child table. Specifically, as shown in the example with Data WS-C3.... in the picture. [![<table class="table table--bordered table--nostripes table-top"> <thead& ...

Tips for adding transparent images (such as logos) to an HTML website: I'm struggling with getting rid of the white background that appears on the website. Does anyone know how

Seeking guidance as a beginner web developer. I am currently working on adding a transparent logo to my website, but the white background is showing up behind the logo. How can I fix this issue? Here is the link to the image - Here is the HTML & ...

What is the best way to create some distance between a div element and the bottom of the body?

Hello, I am attempting to center a div within my body. The div has a minimum height of 400px, but its size can expand based on the content it holds. When I add more content to the div, it grows accordingly, but it ends up touching the bottom of the div. I ...

The two <p> elements are being pushed to the right column, which is not their intended display

A snippet of less.css code is available at this link: #content { overflow: hidden; width: 100%; p { float: left; width: 465px; padding: 0px 25px 0px 35px; margin: 0px; br { line-height: 2. ...

Create a dynamic HTML page using JavaScript

When I click on the following links: How can I create a new page using JavaScript? Create and dynamically append elements I'm looking to dynamically add HTML elements with JavaScript within a div, but I don't want my code to become overly comp ...

Tips for adjusting the page display when errors occur during form submission

Within my django application, I have designed a page featuring a button that controls the operation of a clock. Initially, the page displays only the button, with a hidden form where users can input details such as their name and description. When the butt ...

unable to apply background to entire section

After using HTML5 and jquery to create a section, I attempted to set an image as the background. However, the image is not filling the entire section, leaving a 2px space around all sides inside the section. Below is the code I used: <div id="container ...

I'm having trouble centering the links in my navigation bar using flexbox, and I'm not sure how to fix it

Struggling with creating a navigation bar for my portfolio-building project. The "Who needs a quote" element is correctly displaying on the left, but I can't figure out how to center align the links "Sports, business, politics". Tried using flexbox op ...

The hover effect is functional on the majority of browsers, with the exception of Safari and Chrome on a Mac computer

Within my html code, there are various tiles containing two images (one in jpg format as the background and one in png with transparency as the foreground) along with a hover effect: When hovering over a tile, the image zooms in towards the position of the ...

Ways to apply distinct styles to various ids and common classes

When dealing with multiple IDs such as id1, id2, and id3 that share common classes like .selectize-input and .select-dropdown, it can become cumbersome to set styles individually for each ID. Instead of writing: #id1 .selectize-input, #id2 .selectize-inp ...

What is the best way to ensure that an image in the navbar changes when hovered over?

In my quest to enhance my skills, I am currently trying to figure out how to create a hover effect on an image within the navbar. My objective is to have the div with the ID of "pic-index" react to hovering over the "HOME" link in the navbar and change the ...

Tips for centrally zooming responsive images without altering their dimensions

I have created a custom jQuery and CSS function that allows an image to zoom in and out on mouseover while maintaining a constant box size. I modified an example code to suit my needs. Check out the demo here: https://jsfiddle.net/2fken8Lg/1/ Here is the ...

Adjusting the alignment of Bootstrap navbar

I'm new to CSS and I want to center the brand logo and links in the navbar. HTML <nav class="navbar navbar-expand-md center"> <a class="navbar-brand" href="http://www.dimsum.dk" target="_blank" ...

Problem with Adjusting Bootstrap Carousel Caption Placement per Slide

Trying to customize the position of each Bootstrap Carousel slide in This Demo. The code snippet below modifies the caption positioning: .carousel-caption { top: 0; bottom: auto; } However, I need to adjust the positions of other slides' ca ...

What is preventing Ellipsis from functioning properly on Internet Explorer 11?

Can anyone help me figure out how to display a single line of text with three dots (...) if it exceeds the width of the container? I've tried using the CSS code below, which works on Mozilla and Chrome, but for some reason, it's not working on I ...

The React website using a Gatsby template is encountering an issue where blog posts are not appearing in sequential order on the page, resulting in unexpected gaps between

I'm currently working with a Gatsby template from html5up and encountering an issue where the block posts are not stacking properly. It seems that due to varying text lengths in each post, there are gaps depending on the screen size. I've made al ...

What is the method for inserting a line break following an input element using CSS?

I am utilizing a service that provides me with dynamic HTML containing labels and inputs as shown below: input:after { content: "\a"; white-space: pre; } <label for="username">Username</label> <input type="text" id="username" nam ...

Adjust the size of col-lg-3

Is there a way to adjust the size of my col-lg based on different screen resolutions? I'm looking for a solution that can change the size of col-lg depending on the screen resolution. For example: .col-lg-3 { /* styles for screens with 1366x768p ...