Create a sleek 2-column design featuring a bonus scroll bar exclusively using CSS styling

In my current project, I have a unique challenge. I am working with a list of flattened div elements and unfortunately, I am unable to edit the HTML markup to add any structures. The first div in the list is quite long, and I would like to place it in a separate column with its own scrollbar. The remaining divs, whose number may vary, should be stacked in the right column. What CSS settings can I use to achieve this layout? I want to avoid using fixed or absolute positioning if possible.

<div id='1'>1</div>
<div id='2'>2</div>
<div id='3'>3</div>
.
.
.
<div id='n'>n</div>

https://i.sstatic.net/HrdCk.png

Answer №1

To achieve the desired outcome, you can utilize Flex. Take a look at this example:

* {
  box-sizing: border-box;
}

.row {
  display: flex;
}

/* Create two equal columns that sit next to each other */
.column {
  flex: 50%;
  padding: 10px;
  height: 300px; /* For demonstration purposes only - should be removed */
}

.column div {
  background-color:#bbb;
  height:50px;
}

.column div:not(:first-child) {
  margin-top:5px;
}
<div class="row">
  <div class="column">
    <div style="height:500px;">div 1</div>
  </div>
  <div class="column">
    <div>div 2</div>
    <div>div 3</div>
  <div>div n</div>
  </div>
</div>

Answer №2

You can implement this layout using the display:flex property to avoid using positioning properties.

.main {
    display: flex;
}

.blue {
    height: 600px;
    background-color: blue;
    width: 200px;
    border: 3px solid black;
    margin-right: 30px;
}

.red {
    height: 150px;
    background-color: red;
    width: 150px;
    border: 3px solid black;
    margin-bottom: 10px;
}
<div class="main">
        <div class="left">
            <div class="blue"></div>
        </div>
        <div class="right">
            <div class="red"></div>
            <div class="red"></div>
            <div class="red"></div>
            <div class="red"></div>
            <div class="red"></div>
            <div class="red"></div>
            <div class="red"></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

What is the best way to mandate multiple input fields in AngularJS?

I am currently working on creating a basic web page with a few input fields that must be filled out to proceed. Below is the code I have so far: <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/l ...

Tips for arranging the items within the slider according to the specified direction (rtl, ltr) in the Owl Carousel slider for Angular

Is there a way to dynamically change the direction of the owl-carousel-o angular slider based on the selected language? Currently, I have set rtl: true in the owl-carousel configuration during initialization. However, when the user switches to a different ...

Is jQuery the key to Masonry's stacking magic?

Hey there, I could really use some assistance with my website at this link: I thought jQuery Masonry would stack the objects closely together, but when I randomize the div boxes, there are large gaps between them. Can anyone explain why this is happening? ...

Concealing Nested Div Elements

Can someone help me figure out why my code is not hiding the two divs within my content div? I need assistance checking my code to see what's causing the issue. Thank you! I have made some edits to my code. Currently, both forms appear under the "War ...

Enhance <th> elements using CSS classes

I'm encountering some issues with HTML tables. The layout of my table is as follows: <table class="shop_table cart" cellspacing="0"> <thead> <tr> <th class="product-remove">&nbsp;</th> <th clas ...

Issue with random pages where global header.php is not showing a specific image

I'm currently revamping a website that was originally developed using codeigniter. The backend is quite chaotic with no clear identifiers for anything. I recently updated the banner in the header.php file, adjusting the style to suit the requirements. ...

Issue with AdminLite 2.4.0 data table functionality malfunctioning

Check out this template that I'm using. I've copied all the contents for the bower_components and dist folders, and made sure to link and require everything properly. There are no 404 errors, only status code 200. Here is a snippet of my code: ...

Page cannot be adjusted to fit the viewport

My goal is to have the page fit perfectly within the viewport, but despite using the body properties below, I am still seeing a vertical scrollbar. body { display: grid; grid-template: .8fr 4fr / 1fr 4fr; max-height: 100vh; margin: 0; } I'm w ...

Font reference in IE and Chrome causing HTTPS to fail

Take a look at in both Internet Explorer and Chrome. The header tags (h1 through h6) all have font specifications that rely on a javascript fonts.com specification. However, there seems to be an issue with rendering properly. Interestingly, the fonts ar ...

What is the best choice for the navigation menu: using `<ul>` or `<div>`?

Is it considered unprofessional to construct a navigation menu without utilizing unordered list tags? For instance, opting for <div> elements instead. <div class="navbar"> <a href="#"> Home </a> </div> ...

Ensure that adjacent elements operate independently from one another

The code snippet provided above showcases four components: StyledBreadcrumbs, FilterStatusCode, Filter, LinkedTable. The FilterStatusCode component enables users to input search data using TagInput. If the user inputs numerous tags, this component expands ...

The height of each list item should expand based on the size of the div contained within it

The HTML markup I am working with looks like this: <ul data-role="listview" data-inset="true" class="stuff site-content lists"> <li> <div class="nearby"> 20 </div> <h1> name</h1> </li> ...

"Troubleshooting: Why Won't My Entire Div Display on the

Struggling with a website rebuild due to my limited knowledge of HTML/CSS. For some reason, this whole div section isn't showing up as it should. Here is the problematic div: <div class="container clearfix"> <div class="border-shade sli ...

The function Mediarecorder.start() is experiencing issues on Firefox for Android and is not functioning

Recently, I've been facing a peculiar issue while developing a web application. The purpose of this app is to capture about 10 seconds of video intermittently from the device webcam and then upload it to a server. For this functionality, I utilized th ...

How to retrieve the same value from multiple selections using Vanilla JavaScript and multiple select options?

Why do we consistently receive the same value and index when using the ctl key to select multiple options? document.querySelector('select').addEventListener('change', function(e) { console.log(this.selectedIndex) console.log(e.ta ...

Employing IF conditions within a form to refine options

I am looking to streamline the options in my form based on the car and transmission selected. I have set up the form, but I am struggling with the JavaScript code. I need help figuring out how to only display certain color options when Car 1 is chosen alon ...

Are HTML's Regular Expressions the Equivalent of JavaScript's Regular Expressions?

I have been trying to utilize the pattern="" attribute in HTML to implement regex, but unfortunately, I am unable to locate a comprehensive list of HTML regex parameters. This has led me to ponder whether the syntax for regex in HTML is similar to JavaSc ...

Connecting mysql workbench data using html: A step-by-step guide

I'm currently creating a user interface for a database system using HTML. I'm a bit stuck on how to access and manipulate the database in MySQL Workbench. Does anyone have any suggestions or sample code that could help me connect them? Thanks! ...

Spinner loading animation not showing correctly

Even though it shows up when I hover over and inspect, the image remains completely invisible. It's saved in the same folder and I believe all the file names are correct, but for some reason, it's just not working as expected. Any help would be g ...

How can I use jQuery to vertically align an element?

Here's my website: Take a look here! I have a menu on the left column that I want to center. Take a look at the image below for a better understanding of what I'm trying to achieve. https://i.stack.imgur.com/ZzprT.png Here is the JavaScript c ...