A design with three columns that stretch to 100% height using CSS styling

I can't seem to figure out the CSS for this layout. Here is the HTML code I have:

<body>
    <div id="main">
        <div id="left">
            menu
        </div>
        <div id="middle">
        </div>
        <div id="right">
            sidebar
        </div>
    </div>
</body>

My goal is to create three columns - left, middle, and right with widths of 25%, 60%, and 15% respectively, all expanding to 100 percent height of their parent element (main). Additionally, I want the main div to have a minimum height equal to the browser window height and a maximum height based on its children.

Answer №1

If you want to achieve this layout using CSS tables, it can be done easily:

html, body {
    height: 100%;
}
body {
    margin: 0;
}
.main {
    display: table;
    height: 100%;
    width: 100%;
}
.left, .middle, .right {
    display: table-cell;
    background-color: lightgray;
}
.left {
    width: 25%;
}
.middle {
    background-color: beige;
}
.right {
    width: 15%;
}

Check out the demo here: http://jsfiddle.net/audetwebdesign/9L8wJ/

To make sure the content fills the height of the viewport, start by setting height: 100% on the html and body elements.

Then, apply display: table to the parent container with height: 100%. Since this is a table, the value acts as a minimum and will fill the vertical screen unless the content is very long, in which case the table height will adjust accordingly.

Add specified widths to the left and right columns, while the middle column will automatically fill the remaining space without calculations.

Lastly, use display: table-cell for the child elements to complete the layout.

If necessary, you can add a wrapper around the content within each table cell for better control over white space between columns, depending on your specific layout and design preferences.

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

How can the position of Bootgrid's pagination element be fixed in relation to its parent container, no matter how many table rows are present?

I've been struggling to keep the pagination section of a JQuery Bootgrid table I'm building in the right position. No matter what I do, it always seems to be aligned with the last row of the table. I attempted setting the container div as relativ ...

Disable the button on smaller devices

I'm trying to make my button take up the full width on smaller screens like mobile devices. Here's what I have so far... Large Device https://i.sstatic.net/TJex1.png Medium Device https://i.sstatic.net/Hvkan.png Small Device https://i.sstatic ...

Utilizing Jquery for draggable/droppable functionality in combination with custom overflow styles

Encountering a challenge with a drag and drop system that utilizes CSS overflow properties to enable vertical scrolling of a list of values. The issue arises when dragging an item between selected and unselected areas, causing the dragged item to disappear ...

Arranging two divs to appear side by side, but they are mysteriously aligning in a diagonal pattern

I'm facing an issue with my navbar's divs not displaying side by side when set to display inline. Here is the HTML code snippet: <!--Nav starts here--> <nav class="navbar"> <div class="navbar-item-set"> ...

Add a CSS style to an element when its parent container is hovered using Angular

I am looking for a way to change the appearance of an element when its container is hovered over using CSS or SCSS. Here are my requirements: - The solution must be implemented within the child component or the sass file, without knowledge of parent-child ...

Rotate CSS elements dynamically using jQuery

I'm trying to figure out how to change the rotation value of an image element in my code. Currently, the rotation is set to 315 degrees, but I want to change it to 0 when a click event occurs. Can anyone help me with this? ...

What could be the reason for this code not displaying buttons on separate lines rather than next to each other?

I am struggling to get the Logo to print followed by all buttons lined up side-by-side. I have experimented with different display properties within the first <div> tag such as block, inline-block, and even removing the display property altogether. ...

Most left-aligned icon on the left, most right-aligned icon on the right, and evenly spaced icons in between

Imagine a scenario where you are presented with a questionnaire that allows you to respond using a slider (HTML range element). Below the div containing the range selector (slider), I have arranged icons that need spacing. The icon on the far left should ...

The CSS theme toggler for Bootstrap

I am currently working on integrating a style switcher following the instructions provided at . However, when I add a title="" attribute to the CSS link, the CSS file fails to load on the page and the styles revert back to default Bootstrap. I have added ...

When hovering over a single list item, only the top border will be displayed without affecting the

Check out the live link provided below: I am attempting to add a border and later an arrow in the middle on hover in the menu. However, the current code places a border over the entire menu, with individual list items on top of that. #menu ul li { margin ...

Integrating fresh fonts into TinyMCE's font selection choices

I recently reviewed a thread regarding Google Fonts and TinyMCE, and I have successfully added new fonts to TinyMCE in the past. However, I am currently facing an issue where I am unable to add a new font called "Samman" that I obtained from MyFonts.com. ...

Sending a value to CSS using a selector

Can CSS be instructed to implement a selector with a specific value that acts as a variable? For example: -- HTML -- <div class-name="div-3"></div> -- CSS -- .div-(x) { width: 100px * x; } ...

What is the best way to incorporate a floating label into an input field?

My goal is to create a form where the label of the input field moves up when the user starts typing, and stays up if they enter any text. However, if the user leaves the input area blank, the label should revert back to its original position. I have tried ...

When the mouse leaves, the input search will automatically change the text color to black

I'm having trouble developing a search input, as I am facing an issue and unable to find a solution. Currently, the search input is working fine; when I click on it, it expands. However, once expanded and I start typing, the text color turns white wh ...

Rails Polymer is experiencing a glitch where the CSS and Polymer elements are not displaying correctly until a page refresh is

Whenever I first load a page, my polymer elements (like paper-input) fail to load their CSS properly. Here is an example of how the page looks before and after refreshing: https://i.sstatic.net/vsIpE.pnghttps://i.sstatic.net/YAFjP.png Below is the code sn ...

What is the best way to trigger a new css animation on an element that is already in the midst of

Let's talk about an element that already has an animation set to trigger at a specific time: .element { width: 100%; height: 87.5%; background: #DDD; position: absolute; top: 12.5%; left: 0%; -webkit-animation: load 0.5s ease-out 5s bac ...

Difficulty with aligning input boxes in ASP.NET Core Razor Pages

I'm struggling to center some input boxes within my ASP.NET Core web application. I've experimented with CSS solutions and tried various HTML approaches like using the class = "text-center", but so far, I haven't achieved the desired results ...

Instead of modifying the selected class, jQuery generates inline styles

Utilizing the following code to dynamically create a class: $("head").append('<style type="text/css"></style>'); var newStyleElement = $("head").children(':last'); newStyleElement.html('.move{transform: translateX(1 ...

IE11 causing issues with CSS 3D animation playback

My experience with this animation in IE11 is not what I expected. I thought it would open like a book. This animation was made using Google Web Designer (I've kept the code short for simplicity). If you want to see how it looks in IE11, click here: ...

Add the application's logo image to the Ionic header along with a side menu

When attempting to place the app logo image in the center or left of the Ionic header with vertical alignment, it seems to shift to the top instead. The code I am currently using to display the logo is causing some issues: <ion-view view-title="<im ...