One column stretching all the way to the window's edge while the other column stays contained within its container

Looking to design a two-column layout where the left column takes up 40% of the container and aligns with it, while the right column expands all the way to the window edge. I managed to achieve this using position:absolute, but I'm curious if there's a better method out there. Check out the image and code snippet below. Any suggestions on improving this setup?

https://i.stack.imgur.com/CPWi1.png

div {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: arial;
}

.header {
  padding: 20px 10px;
  background: #EEE;
}

.container {
  max-width: 1000px;
  margin: auto;
  display: flex;
  gap: 0;
  position: relative;
}

.container.wide {
  width: 100%;
  max-width: unset;
}

.relativediv {
  position: relative;
}

.absolute-container {
  width: 100%;
  max-width: 1000px;
  padding: 20px 10px;
  position: absolute;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 50%;
}

.container.wide :nth-child(1) {
  width: 40%;
}

.container.wide :nth-child(2) {
  width: 60%;
  min-height: 500px;
}

.container.wide :nth-child(2) img {
  height: 100%;
  width: 100%;
  object-fit: cover;
  display: block;
}
<div class="container header">
  Header
</div>

<div class="relativediv">

  <div class="container wide">
    <div></div>
    <div>
      <img src="https://i.picsum.photos/id/0/5616/3744.jpg?hmac=3GAAioiQziMGEtLbfrdbcoenXoWAW-zlyEAMkfEdBzQ" />
    </div>
  </div>

  <div class="absolute-container">
    <div class="content">
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
    </div>
  </div>

</div>

Answer №1

You can easily achieve a 2 column layout using Flexbox. If you want to vertically center the text in your left column, Flexbox can help with that as well:

.relativediv {
  display: flex;
  flex-direction: row-reverse;
}

.container {
  width: 60%;
  max-width: 1400px;
}

.container img {
  width: 100%;
}

.absolute-container {
  flex-grow: 1;
  display: flex;
  align-items: center;
}
<div class="container header">
  Header
</div>

<div class="relativediv">

  <div class="container wide">
    <div></div>
    <div>
      <img src="https://i.picsum.photos/id/0/5616/3744.jpg?hmac=3GAAioiQziMGEtLbfrdbcoenXoWAW-zlyEAMkfEdBzQ" />
    </div>
  </div>

  <div class="absolute-container">
    <div class="content">
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
      <p>Lorem ipsum dolar sit smit is dummy text. </p>
    </div>
  </div>

</div>

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

PHP code for uploading multiple images at once

I am currently facing an issue with uploading multiple files at once and not getting the desired result. Below is my code snippet: <?php if (isset($_FILES['uploadfiles'])) { print_r($_FILES); } ?> <form action="index.php" method="po ...

How can I use JavaScript to create a drop-down menu that only appears after selecting the previous one?

<div class="row"> <div class="col-md-4"> <label for="selectCustomers">Customer Select</label> <select class="form-control pointer" name="tableCustomers" id=" ...

Passing form values from JavaScript to a JSP page - a comprehensive guide

I am working on a sample HTML page that includes inline JavaScript for calculating geocodes and retrieving latitude and longitude values. My question is, how can I submit all the form values along with the latitude and longitude returned from the showlocat ...

jQuery datatables provide a powerful feature for column filtering using jQuery functions

Looking for advice on how to add a filter to my jQuery datatable column that contains checkboxes. I want the filter to be a drop-down menu with options for "checked" and "unchecked", so that when a user selects one of these options, only the rows contain ...

Craft a search bar inspired by Google's iconic design using CSS styling

I need to recreate a custom input styled like the Google Material Theme design. This is the desired outcome: https://i.stack.imgur.com/QU5dp.png While I am aware that frameworks/libraries can achieve this, it is part of my assignment to create it from s ...

What is the process for creating two columns with an input box beneath them?

I am facing a challenge with my code. I am struggling to create the desired design where there are two columns and below them an input box that will be displayed when a button is pressed. The design I am aiming for can be viewed here: enter image descripti ...

Displaying HTML content using Typescript

As a newcomer to typescript, I have a question regarding displaying HTML using typescript. Below is the HTML code snippet: <div itemprop="copy-paste-block"> <ul> <li><span style="font-size:11pt;"><span style="font-family ...

Which font file format is the most suitable for my website?

I've been doing some research on fonts for my website, and I've come across various formats available. Now I'm curious about what the standard format is or if there are multiple standard formats. .TTF (True Type Font) .EOT (Embedded OpenTyp ...

Is it necessary to alter the number of rows or columns in the table?

I'm having an issue with my code where the table is not changing the number of rows based on the selected input option. It seems to only read the first value of the select id and does not update the rows accordingly. Can someone help me identify the m ...

Ensure that the main div remains centered on the page even when the window size is adjusted

Here is the code snippet: <div id="root"> <div id="child1">xxxx</div> <div id="child2">yyyy</div> </div> CSS : #root{ width: 86%; margin: 0 auto; } #root div { width: 50%; float: left; border: ...

Extracting the number of likes from each post on a specific profile using Python scrapy

Here is the code snippet that I am currently working with: #IMPORT THESE PACKAGES import requests import selenium from selenium import webdriver import pandas as pd #OPTIONAL PACKAGE, BUY MAYBE NEEDED from webdriver_manager.chrome import ChromeDriverManage ...

Import css background-images from a separate local directory that is located outside the root directory of the Next JS

I am facing a challenge with hosting a next.js app within the file structure of a parent website. I need the CSS in the app to use images that are located outside the app's file structure but within the parent website's file structure. Here is a ...

The text exceeds the maximum width of the table column

Currently, I am working with a table and utilizing the <col> tag to define column widths. However, I have encountered an issue where one of the columns, set at 5% width, contains a title that is 16 characters long, wider than the allocated 5%. As a ...

Ajax immediately going to the error section

I'm having trouble with my ajax as it always goes straight to the error part. Below is my code along with comments on the lines I'm unsure about: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script&g ...

What steps can be taken to prevent alternate scrolling text from extending beyond the boundaries of its parent element?

I'm attempting to create a scrolling effect where the text moves back and forth within its container. The current issue I'm facing is that the text goes beyond the width of the parent container before scrolling back. I want the text to smoothly s ...

What is the best way to capture the output of a script from an external website using Javascript when it is returning simple text?

Recently, I decided to incorporate an external script into my project. The script in question is as follows: <script type="application/javascript" src="https://api.ipify.org"> </script> This script is designed to provide the client's IP ...

Filtering tables in Angular 6 using checkbox options

I have a functional code snippet that filters a table using checkboxes. However, I am facing an issue when unchecking a checkbox. It does not return the original array as expected. .html <ng-container *ngFor="let group of groups"> <label cla ...

Begin counting when a particular div element is visible on the screen

I have a plugins.init.js file that contains a try-catch block which runs on page load. I am looking for a way to execute this code only once when the div with the class counter-value comes into view. Is there a method to achieve this? try { const count ...

Elements displaying outside of block 'a' tag

I have a set of <a> elements that are styled with display:block. These contain various nested <divs>, for example: <a href="#" class="sliderframe"> <div class="container-caption"> <div class="slider ...

Troubleshooting problem with Ajax responseText

Can an ajax responseText be received without replacing the existing content? For instance: <div id="content"> <p>Original content</p> </div> Typically, after running an ajax request with a responseText that targets id="conten ...