Positioning a div absolutely while still keeping the integrity of the page layout

I'm in the process of setting up a blog page on my website with a design that includes two columns. The first column, known as .col_1, is fixed in width and is showcased in red. The second column, represented by .col_2, occupies the remaining space and is displayed in blue. Within Column 2, there is a rich text block called .rich_text, highlighted in green, where all blog headings, text, and content are contained within a specific maximum width.

I am aiming to have all tables within the .rich_text block extend beyond its borders and reach the edges of .page_body, consequently spanning the entire width of .page_body. I previously utilized

position: absolute; left: 0px; right: 0px;
in the styling of .table_container_abs to achieve this effect; however, this positioning caused the table to overlap other content in the .rich_text block.

Take a look at the live example of my webpage layout embedded below. Now, my question is: How can I widen these tables to touch the borders of .page_body without the use of JavaScript, while also maintaining proper interaction with the elements in the rich text block?

.page_body {
  width: 100%;
  display: flex;
  position: relative
}

.col_1 {
  width: 100px;
  flex-grow: 1;
  background-color: #FFC9C9
}

.col_2 {
  flex-grow: 3;
  background-color: #C9DEFF
}

.rich_text {
  max-width: 300px;
  background-color: #F0FFFA
}

.table_container {
  width: 100%;
  height: 100px;
  color: white;
  background-color: #656565
}

.table_container_abs {
  left: 0px;
  right: 0px;
  position: absolute;
  height: 100px;
  color: white;
  background-color: #656565
}
<div class='page_body'>
  <div class='col_1'>Post navigation</div>
  <div class='col_2'>
    <div class='rich_text'>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
      <br><br>
      <div class='table_container'>Table</div>
      <br>
      Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
      <br>
      <div class='table_container_abs'>Absolute table</div>
    </div>
  </div>
</div>

Answer №1

To prevent text overlapping without using the absolute position property, follow these steps:

1 - Re-position the table_container_abs div outside of col_2 and make it the last direct child of the page_body div.

2 - Apply the flex: 0 0 100%; property to the table_container_abs class and remove the absolute position, top, and left properties.

3 - Add the flex-wrap: wrap; property to the page_body class to wrap the contained boxes.

By following these steps, you can ensure your boxes do not overlap. Enjoy the clean layout!

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

Login block for Episerver

I'm brand new to episerver cms and I'm trying to add a "login block" to the top right corner of my home page where front-end users can log in. I've created a “LoginBlock”, ”LoginBlockController” along with a class called “LoginForm ...

Navigation bar theme toggle malfunctioning as anticipated

I'm experiencing an issue with the navbar theme change functionality. Whenever I click on the dark mode button, the theme changes for a brief moment and then reverts back to light mode. <!doctype html> <html lang="en"> <hea ...

Show another default value once an option has been chosen

I am looking to create a functionality where, after a user selects an option, the input will change to display "select another option" instead of showing the name of the selected option. For example: <select> <option value="" selected&g ...

Adding external stylesheets or libraries in Express is a simple process that can greatly

Currently, I am in the process of developing a todo application using the express framework on a node server. The starting point for my application is an index.ejs file located in the same folder as my jquery.min.js file. However, when I attempt to include ...

Utilizing jQuery to assign a value to a SPAN tag

In my code, there is an element with the following syntax: <span id="userName.errors" class="errors">Enter Your User Name </span>. I am interested in utilizing jQuery to delete either the text 'Enter Your User Name' or any element tha ...

Is there a different option to use instead of the onChange event for the <select> element in ReactJS?

As I work on developing a Component with numerous <select> elements, the challenge arises when only one option is available and onChange event fails to trigger. Is there an alternative event in ReactJS, such as onSelect, that can be employed for this ...

Utilizing numerous copies of a single plugin

I recently integrated a plugin called flip-carousel.js into my website and here is an example of how it looks on the site. Check out the sample implementation Now, I encountered an issue when trying to use multiple instances of the same plugin. When init ...

"Utilizing Flask to efficiently manage a multitude of buttons and seamlessly update a

I am working on a web application similar to mini-tweets. The content for the posts is retrieved from a database and I want to include an 'up vote' button for each post, similar to the image shown below. https://i.sstatic.net/kJySO.png Each pos ...

Adding multiple elements with varying content to a separate division

I am attempting to combine two div elements into a single div, but I'm encountering difficulties. Despite thoroughly examining my code, everything appears to be correct. Here's what I've tried so far. To assist me in achieving this, I am ut ...

Produced inputs and preset values

I have a question regarding the use of generated input elements in my App's form. I want to keep it as simple as possible, which is why I am using native form reset for these elements. It appears that the 'default value' becomes bound to th ...

Styling elements using flexbox and various other divs

Looking to style a webpage with CSS to achieve this particular layout: https://i.sstatic.net/K3x0A.png The objective is to make the page responsive where the red and blue columns (left and right) have fixed widths. The center column should be collapsible ...

What is causing the chat-widget to display a null value for the style read property?

Could someone assist me with hiding the Widget-chat? I keep getting an error that the property of style is null. Any help would be greatly appreciated. Thank you in advance. document.getElementById("chat-widget").style.display='none'; ...

The Chrome extension for the New Tab Page is taking the spotlight away from the address bar

It appears that with the latest version of Chrome, extensions that previously had the ability to override Chrome's New Tab Page and take focus away from the Omnibox no longer have this capability. Is there a different method now to give focus to an i ...

Grab the SVG and resize it to a smaller scale

I have a small application built using Raphael.js that creates a node network with SVG and reorganizes it based on user selections. My goal is to capture the SVG image I've created and display it in a "mini-map" format at the bottom of the screen. Si ...

Jquery Timer that can be toggled on and off with a single button

I'm really struggling to find a way to make this work smoothly without any bugs. The button in the code below is supposed to perform three actions: Initiate a countdown when clicked (working) Stop the countdown automatically and reset itself when it ...

Adding to the beginning of a list in JQuery mobile

Having trouble figuring out how to prepend my list in jQuery mobile while keeping the divider on top of the most recent item added. I attempted to prepend the newly added item, but it ended up shifting the divider to the bottom instead. function loadScan ...

Is it feasible to incorporate one iOS app within another iOS app through in-app purchasing or subscription?

Simply put, we are creating interactive content in Flash that we want to distribute through an iOS app either by in-app purchase or subscription. In our testing, we have found that Flash can produce standalone iOS apps that work well for our needs. Instea ...

The mysterious height phenomenon when setting the width of a list item with jQuery

Consider a basic ul and li setup similar to this: <div id="middle"> <ul> <li> <a> bridal </a> </li> //.... </ul> </div ...

Utilize JavaScript/jQuery to check for upcoming deadlines in a SharePoint 2013 list

I need to check if an item is due based on its date. When a user creates an item with a date in the format MM/DD (e.g., 06/15), I want to determine if that date falls within the next 30 days, turning it red, within the next 60 days, turning it orange, or g ...

Breaking down a div with jQuery - tips and tricks!

I have a question regarding jQuery. Consider the following structure: <div class="page"> <p>Lorem ipsum....</p> <p>Lorem ipsum....</p> ... </div> I want to transform it into this format: <div class="pa ...