How to perfectly align div columns in a fluid layout using Bootstrap 2

I created a basic two-column fluid layout using Bootstrap 2. One column features two div elements, while the other contains three div elements. Both columns are set to span6. You can view the fiddle here.

I tried adjusting the heights of the two div elements in the left column with CSS, aiming for the top one to occupy 62.5% of the browser window height and the bottom one to take up the remaining 37.5%. I wanted to achieve similar height ratios for the three div elements in the right column. However, I encountered several questions/issues:

  1. The block/div heights don't extend fully to fill the window vertically, and the individual block/div heights remain unchanged.
  2. How can I make the combined height of the two div elements on the left match that of the three div elements on the right, while maintaining the specified relative height ratios within each column (
    left: 62.5%, 37.5%; right: 35%, 30%, 35%
    )?
  3. Is there a way to adjust the padding between the blocks/divs?

I'm hoping all these objectives can be accomplished without using any Javascript.

Answer №1

I have attempted a solution that may assist you. Here are the answers:

  1. The height of each BlocX div remains unchanged because the height of body has not been defined. In your case, the body's height is set automatically based on its content.

  2. Refer below for more details.

  3. The "paddings" you mentioned are actually margins in the .well class. You can either avoid using this class or override its settings.

Here is the updated code:

HTML:

Removed the .well class, everything else remains the same.

CSS:

html{height:100%;}

.body-background {
    padding-top: 10px;
    background-color: #D1D1D1;
    height:100%;
}
.container-fluid, .row-fluid, .span6
{
    height:100%;
}

#A-b {
    min-height: 62.5%;
    height: 62.5%;
    background-color: #FFE0C2;
}

#B-b {
    min-height: 37.5%;
    height: 37.5%;
    background-color: #4D4D4D;
}

#C-b {
    min-height: 35%;
    height: 35%;
    background-color: #969696;
}

#D-b {
    min-height: 30%;
    height: 30%;
    background-color: #57BCFF;
}

#E-b {
    min-height: 35%;
    height: 35%;
    background-color: #183547;
}

We have set the html and body elements to have a height:100%, followed by doing the same for .container-fluid, .row-fluid, and .span6. This results in the display shown in this DEMO.

NOTE: For resolutions less than 768px, utilize media queries to adjust the height of BlockX and other elements accordingly. Avoid setting heights directly on span6, row-fluid, etc. This example serves as a guide - consider creating custom classes to modify Bootstrap's existing classes for your live website.

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

Struggling to vertically align text beside an image in Twitter Bootstrap - any suggestions?

I'm currently incorporating Twitter Bootstrap and facing a challenge with centering text vertically next to an image that exceeds the size of the text. The use of line-height is not feasible as the text spans multiple lines and may be subject to addi ...

What is the best way to style a select element to achieve this appearance?

https://i.sstatic.net/4yGqf.png Currently working on converting a .psd file to html/css and encountering difficulty with a unique looking select element. Struggling to find a suitable example online for reference. Wondering if this design element is indee ...

What is the best way to choose a particular radio button from a group of radio buttons using typescript?

Is there a way to automatically select a specific radio button when an item is chosen from a dropdown menu on the webpage using a TypeScript function that is triggered by the dropdown selection? ...

PHP and MySQL not displaying the image

I have written the following code to display information about an image, including its file, but for some reason, it is not appearing on the screen. <?php include('config/dbconnect.php'); if(isset($_GET['id'])) ...

Choosing a Google Form dropdown option using Selenium in Python without the select tag specifically

I've been attempting to choose a dropdown option from a Google Form using Selenium and Python, but I haven't had any luck so far. I've tried various methods, including using the Select class (which doesn't work because the dropdown for ...

Maximizing space efficiency in Bootstrap 5

Hello there I have a query; I am currently utilizing Bootstrap 5 for my website, and it's working well. However, I would like Bootstrap to fill the entire page instead of just 80%; (Refer to image) https://i.sstatic.net/Iswmu.jpg <head> ...

Prevent Scrollbars in a Div

At the bottom of my website, there is a carousel slider that moves left and right when I scroll over it. Is there a way to disable this movement? If anyone has any suggestions on how to disable this feature, I would greatly appreciate it. ...

Eliminate borders surrounding WordPress text widgets

Looking for some help with removing the border around the widgets on my home page. Despite my theme's CSS removing borders universally, I thought targeting specific Div text widgets (such as text-7, text-6) would do the trick. While I can control the ...

What is the best way to showcase data from an external model without having to constantly refresh the page?

I am attempting to showcase a User's name at the top of a box where they input their Employee # in a form, all done without needing to refresh the page. The process is simple: the user enters their # and upon clicking or tabbing onto the next field, ...

Color overlay on top of image background

I'm struggling to create a striped colored background with a narrow center single color background on top for showcasing articles and photos. However, I am unable to get the colored background to display correctly. Despite trying different approaches ...

"Enhancing User Interaction with jQuery Hover State Dropdown Menus

Here's my issue: I've created a drop-down menu and I want the text color to change when hovering over the menu. Additionally, I'd like the hover state to remain active when hovering over the submenu. Currently, I'm using this code: $( ...

Guide to smoothly scroll to the top of an element containing collapsible panels using Jquery

I've encountered an issue with a series of divs that are set to toggle the state of a collapsible div upon clicking (similar to an accordion widget). The functionality works as intended, but I'm facing a challenge - I want the page to scroll to t ...

What are some ways in which I can utilize the Ember Handlebars helper?

Similar Question: Using logical operators in a Handlebars.js {{#if}} statement Below is the code snippet provided: {{#each dataArray}} <li>{{#isTrue idVal1 idVal2}} display some text1 {{else}} display some text2 {{/isTrue}} & ...

Having trouble unselecting the previous item when selecting a new item in Reactjs

I have a list of items and I want to change the background color of the currently selected item only. The previously selected item should deselect. However, at the moment, all items are changing when I click on each one. Can anyone help me solve this issue ...

Issues with CSS transitions/animations not functioning properly across different browsers

Take a look at this FIDDLE Link. I'm facing an issue where the animation works smoothly in Firefox, but it's not functioning as expected in Chrome. Kindly open the fiddle in both browsers (Chrome and Firefox), hover over the image, and notice t ...

Tips for setting the color of hyperlinks in a UIWebView

I'm struggling with formatting a short plain text string, which may include a weblink, in a UIWebView. When I use loadHTMLString, the font style and size appear incorrect. After searching extensively, I ended up embedding the text in a makeshift HTML ...

The particles.js with absolute positioning is currently overlapping my div with relative positioning

Visit this link <div class="outer-container"> <div id="particles-js"> <div class="your-content"> <article id="3" class="bg-dusk transition md:group-hover:opacity-50 md:hover:opacity-important md:hov ...

Looking for a different method to remove a list item within an unordered list using CSS instead of HTML

I am currently working on designing a mock-up website using CSS codes. If you want to see the mock-up website, you can visit: Here is the specific list I am referring to: https://i.sstatic.net/HA3fC.jpg This is the expected outcome: https://i.sstatic.ne ...

Automate the vertical resizing of a div element using code

Currently, I am utilizing Angular4+. I am looking to dynamically resize a div vertically, but I am unsure of how to go about it. I am uncertain about where to even begin and how to accomplish this task without resorting to using jQuery. Are there any sugg ...

Following a successful ajax response, the functionality of the JavaScript ceases to operate

Once an Ajax request is successfully sent, the jquery.hover() function no longer works with the new content on the page. Is there a method to refresh the script without reloading the entire div through another ajax request, in order to make it functional ...