Can document flow easily be restored after using position:absolute, or is there a better alternative available?

I've been facing a challenge in finding an efficient way to center a div. I prefer clean html and avoid unnecessary divs just for centering purposes. To solve this, I opted to use position:absolute.

Although I am aware that position:absolute disrupts the document flow, I'm looking for a solution to "undo" this disruption. Currently, I have a div with 100% width, 20% height, vertically centered. Inside this div, there's a paragraph, and another paragraph outside of this div at the bottom of the page - but due to using position:absolute, the copyright notice displays before the div.

Is there a method to restore the document flow without having to apply margin-top: npx; to every post-div element on the page?


JSFiddle:

HTML:

<div id="container">
    <p>Hello</p>
</div>
<p>Copyright Notice here</p>

CSS:

*
{
    outline: none; outline: 0; border: none; border: 0; margin: 0; padding: 0;
}

#container
{
    width: 100%;
    height: 20%;

    position: absolute;
    left: 0%;
    right: 0%;
    top: 40%;
    bottom: 40%;

    background-color: khaki;
}

p
{
    text-align: center;
}

Answer №1

Ensure your copyright notice is placed at the very bottom of the page.

p { position: absolute; bottom: 0px; /* or adjust as needed */ }

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

Looping through iterations to create circular patterns

How can I fix my code to draw multiple circles in a loop instead of just one? var ss_links_canvas = document.getElementById("ss_links_canvas"); ss_links_canvas.width = images.length * 41; ss_links_canvas.height = 25; var ss_links = ss_links_canvas.getCont ...

What is the best way to replicate the orange outline when focused?

I am in the process of creating a series of divs that can be navigated by the user using the tab key. I would like to incorporate the standard orange focus outline for these elements. Is there anyone who can provide guidance on how to achieve this? I unde ...

Is there a way to ensure that the size of the second div box can adjust dynamically in CSS?

Is there a way to make multiple boxes expand dynamically in size when one of them contains more words? Currently, the problem is that only the box with more text expands while the others remain unchanged. I want all the boxes to follow the same size dynami ...

Tips for invoking a function using ng-model together with the ng-model value

Within a div element, I have a text field where I am using ng-model to capture the value. I need to trigger a function for validation when a date is entered in the text field. How can I achieve this while still utilizing ng-model? Any suggestions on how to ...

Can an image be allowed to overflow outside of a div without changing the div's size?

Starting Point I am in the process of designing a layout with Bootstrap 4. Here's a rough representation of what I am aiming for: https://i.sstatic.net/7QTpk.jpg And here is the basic structure: <div class="row"> <div class="col-12 c ...

React custom slider component is failing to meet expectations

I've been working on enhancing my React skills and building my portfolio. Instead of using a library, I opted to create a custom slider using the code below: const ProjectWrapper = styled.div` .container { transform: translateX(-$ ...

Tips for aligning Picture boxes using CSS

As a newbie, I recently received training in HTML, CSS, and a bit of JavaScript. Currently, I am involved in a project where I display the latest news from an API. The technical aspects of fetching data from the API using JavaScript are handled by a senior ...

Aligning multiple items to the right using Flexbox

While it's common knowledge how to align one item to the right in flexbox, what about aligning multiple items, like the last two elements, to the right and the rest to the left? Take a look at this example where I want elements with the class .r to be ...

I am looking for a way to create responsive boxes specifically for lg, md, and sm modes in Bootstrap 5

I need my boxes to be col-12 in col-sm and col-6 in col-md. Can someone please advise me on what steps I should take? If there is a tutorial addressing this issue, kindly share the link with me. Thank you. <div class="content container-fluid col ...

CSS - uniform sizing for border images

INQUIRY: I am looking for a way to maintain a consistent border image size when resizing a div. I have considered using pseudo elements, but I'm wondering if there is a simpler solution? HTML: <div id="resizable" class="ui-widget-content"> & ...

How to make sure that an element overflowing its container always starts from the top

My website has a section called <mat-drawer-container>, which contains a list of items called <mat-selection-list>. However, when the number of elements in the list exceeds the display height and scrolling is necessary, the scroll position star ...

Transforming a numerical function into an HTML span tag: A quick guide

Looking for assistance with updating the last line. The goal is to display the current month, obtained from the getMonthText variable, within the <h1><span id="month_year">&nbsp;</span></h1> Starting code. The issue arises to ...

The challenge of using <p></p> tags with Bootstrap 4, HTML, and CSS

Having trouble separating multiple paragraphs within a division? Let's take a look at the code snippet in question: <div class="row"> <div class="col-md-12 d-flex justify-content-center padding-top"> <p>IMPORTANT LEGAL D ...

There seems to be a problem with the Bootstrap Container and Container Fluid

I am currently utilizing Bootstrap 3.3.7 and have incorporated buttons to enhance the content on my webpage. Upon using container-fluid, I noticed that it does not expand the content across the entire page but rather confines it to the center area of the ...

barchart rendered in SVG without the use of any external libraries

Creating a stacked barchart with SVG and HTML without relying on any third-party library has been quite a challenge. Despite searching extensively online, I have not come across a single resource that demonstrates how to build a stacked bar chart using pla ...

Verify if a checkbox is selected using an if statement in a Django template

I am currently working on a registration form that requires the user to check a checkbox in order to accept the terms and conditions before they can submit the form. The submit button should be disabled until the checkbox is checked, at which point the but ...

The usage of line breaks within the <textarea> and <pre> elements is crucial for maintaining the formatting of text

In this box, you can enter text. If you reach the end of the line with letters, it will automatically continue on a new line. Once you click on 'update details,' the letters will be saved in a database. https://i.sstatic.net/q2Y1Z.jpg On the &a ...

Rearrange the columns as the window size decreases

My webpage currently has two columns, left and right. However, I want the right column to appear above the left one when the window size is reduced. Currently, as the window shrinks, the right column drops down below the left column instead of moving abov ...

Unable to set a specific position for adding a new option in a dropdown menu

I have implemented a semantic UI dropdown using the code below: $('.ui.dropdown') .dropdown() ; <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <l ...

Newbie inquiries regarding the process of migrating a CRUD application to PhalconPHP

I have recently delved into using PhalconPHP 1.3.1 for an application related to my master's thesis. While it is still a work in progress, I am currently focusing on implementing CRUD functionality and refining the user interface. This endeavor marks ...