Unusual trio of divs lined up next to each other

I typically work with tables, but I need to rearrange some div elements by dragging and dropping them. I decided to try a table-less approach this time around.

Here's my goal:

I want the spacing between all elements to be 24px. My main issue is getting the divs (1, 2, 3) to occupy 100% of the available space without extending beyond the main container.

This is what my code looks like so far:

html

<div id="mainContainer">
<div id="topContainer">Just the top one
</div>
<div id="table">
    <div id="Line1Container">
    <div id="container1" class="container">1
    </div>
    <div id="container2" class="container">2
    </div>
    <div id="container3" class="container">3
    </div>
</div>
<div id="Line2Container">
    <div id="container4" class="container">4
    </div>
    <div id="container5" class="container">5
    </div>
    <div id="container6" class="container">6
    </div>
</div>
</div>
</div>

And here's my CSS

#mainContainer {
    border: 1px solid lightgray;
    position:fixed;
    top: 80px;
    bottom:20px;
    left:80px;
    right:80px;
    overflow-y: scroll;
    overflow-x: hidden;
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}

#topContainer {
    border: 1px solid lightgray;
    border-radius: 10px;
    margin-left: 24px;
    margin-right: 24px;
    margin-top: 24px;
}

#table {
    display: table;
    margin: 24px;
    width: 95%;
}


#Line1Container, #Line2Container {
    display: table-row;
}

.container  {
    border: 1px solid lightgray;
    display: table-cell;
    width: 33%;
    border-radius: 10px;
}

So far, I've tried using the table-cell method, but I previously attempted the float: left technique as well.

Appreciate any help!

Answer №1

CodePen

Combining px values with % values for dynamic sizes can create issues. It's better to use x% instead of 24px. Also, consider applying float: left to the "cells"

Answer №2

Have you considered using a table to separate the divs? This way, with td padding, there will always be 24px between them.

Take a look at this fiddle:

http://jsfiddle.net/5zfEq/

Additional code:

#Line1Container {
    padding:12px;
}
#inner-table {
    width: 100%;
}
#inner-table td {
    padding: 12px;
}

This is based on @Edifice's fiddle .... thank you! ;)

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

Utilize the id in AngularJS to bring attention to a specific row within a table

I am brand new to using angularjs. I currently have a table structured like this: HTML <table class="table table-striped" id="manageResumeTable"> <thead class="text-center text-info text-capitalize"> <th class="text-center col- ...

Removing a blank line from a null variable in PHP and appending a backspace to it to display HTML text

How can I remove the empty line for a null variable? For example: $line1 = "Hello All"; $line2 = "Hello You"; $line3 = "Hello Me"; $line2 = null; Now when I echo echo "$line1<br>$line2<br>$line3"; it shows an empty line in the middle whe ...

How can HTML output be automatically indented?

Seeking a way to automatically indent the HTML generated by my PHP script. I currently use HTML Purifier for validating internal textbox inputs, but I have reservations about using HTML Tidy due to its lack of active development and numerous reported bugs ...

Expand a div without causing any displacement to surrounding elements

If you have 4 colored divs (red, yellow, green, blue), with 2 per row, and need to expand the second (yellow) without creating a gap under the red, check out this solution. The blue will be positioned underneath the expanded yellow. For a live example, vi ...

Obtain a collection of hexadecimal color codes within an unordered list (<ul>) by using AJAX to fetch data from

I have a div containing various product options, each with a different color swatch: <div class="productOptionPickListSwatch"> <ul> <li class="swatch hasPreview swatchOneColour"> <label for="e3385b72a9a0c62514e ...

What is the best way to ensure that the image appears directly below the text, rather than being obscured by the content of the

Hey there! I'm pretty new to StackOverflow and currently diving into fullstack web development. Just the other day, I embarked on creating my very own website, but now I find myself in a bit of a pickle. It seems that my image keeps appearing behind t ...

Tips for eliminating extremely fine light and dark borders from a navigation bar

I recently had a client bring to my attention a very faint light line and thin dark line present in the active link of their navigation bar. Despite being barely visible, it is still there. I have attempted to adjust the CSS, but given that the lines are l ...

Show a specific item when selecting an option from a dropdown menu

Hey there, I have a question regarding creating a theme for the Genesis Framework. Right now, I'm facing a challenge with one particular element. Here's the situation: I've got two drop-down lists, but I only want the second one to be visib ...

The title on my iOS app is off-center towards the left side

My title in the application is not centered on iPhone, but it appears fine when accessed through a browser. How can I fix this issue? Here is my HTML code: <div data-view="Moobile.ScrollView" class="component-testpage-view"> <div data-role="n ...

What is the best way to transform an HTML document into a PDF file using Delphi programming language?

Is there a library or component that can efficiently handle this task without breaking the bank? Edit: Oops! I forgot to mention that this is for a web app and we can't assume that the user has a PDF driver installed. ...

Retrieving selected options from a jQuery mobile multiselect for database storage

I'm currently working on extracting values from a select list in a jQuery mobile application. Here's the markup for my select element: <div data-role="fieldcontain"> <label for="stuff" class="select">Stuff:</label ...

How can I assign a value other than a string to a placeholder or vue property?

As I develop a content management system using Nuxt and Pug/Jade, I am looking for an efficient way to create a list of input fields for users to enter information. My idea is to use the v-for directive to render the list and dynamically set the value and ...

The Angular JS routes are not properly loading the required file from the provided TemplateURL when receiving a response from Node

I am trying to retrieve data from a MySQL database using node (routes.js) and have the results injected into club.html, which is then dynamically updated in index.html using ng-view. However, it seems that the JSON response from node is displaying directly ...

How to make a checkbox list appear bold when checked in AngularJS?

<div class='someClass'> <label ng-repeat="item in itemList"> <input type='checkbox' checklist-model='itemCheckList' checklist-value='item.name'> <span class=& ...

Guide on displaying an EJS page with AngularJS on a Node.js server

Having an issue with rendering an ejs page through nodejs. The page works fine independently, but fails to load when rendered via nodejs. Any help would be appreciated. ejs page: <html> <script src="/home/aniruddha/Downloads/angular.js"></ ...

In order to avoid conflicts, please update the version code of your APK as there is currently one with version code 1. How can I go about changing the version?

My attempt to upload an apk file on Google Play has hit a roadblock. The apk file was created using Unity3D. Google Play is giving me an error message stating that I need to use a different version code for my APK because a version with code 1 already exis ...

Tips for minimizing separation by utilizing timeline panels in Bootstrap

Is there a way to decrease the spacing between each panel? Right now, they are too far apart and when I fill up a lot of space, the navigation bar always shows up. I don't want that horizontal bar to be visible. I want to avoid that bar from appearin ...

The footer looks off-center when zooming in or out

I'm currently facing an issue with the footer on a website. When viewing it at 100% size (normal size), the footer appears aligned perfectly. However, upon resizing it, the alignment is lost and it shifts to the left instead of staying centered. Scr ...

The ng-controller directive is not functioning accurately

I attempted to execute the following basic HTML: <!DOCTYPE html> <html ng-app="tempApp"> <head> <script src="js_libs/angular/angular.min.js"></script> <script src="js_libs/angular/bootstrap.js"></script&g ...

Exploring the World of Design in Next JS

When styling a Next.js app, is it necessary to use import styles from "./stylesheet.css" and apply classes with className={styles.aClassName}? If so, what if I need to style an element by ID or tag name? Is there a way to style a Next.js app li ...