What is the best way to create a three-column layout that completely fills the width of a page, utilizing pixel measurements on two of the columns

Click here for the jsFiddle link:

Is it possible to make div2 and Button2 fill the remaining width of the window while using pixel measurements on columns 1 and 3?

This formatting will be applied to a form where a textbox needs to adjust its size based on two fixed fields.

Appreciate your help!

CSS Styles

td { border:solid 1px #000; float:left; }

#div1 { width:100px; border:solid 1px #000; float:left; }
#div2 { border:solid 1px #000; float:left; }
#div3 { width:100px; border:solid 1px #000; float:right; }

#Button1 { width:100% }
#Button2 { width:100% }
#Button3 { width:100% }

HTML Markup

<div id="div1">
    <button id="Button1">Button 1</button>
</div>
<div id="div2">
    <button id="Button2">Button 2</button>
</div>
<div id="div3">
    <button id="Button3">Button 3</button>
</div>

Answer №1

To address this issue, a potential remedy involves relocating the second DIV to the lower section and adding margins to it without utilizing float: Take a look at this example on JsFiddle

Answer №2

From what I understand, there are just a couple of ways to accomplish this:

  1. Utilizing tables - although not everyone is a fan of this approach. Personally, I believe it's acceptable for the overall design as long as you don't get too carried away with nested tables and such. Kalle's response addresses this method

  2. Using absolute positioning to specify all four corners. I recently came across this technique and it performs really well. It is compatible with all major browsers.

Here is an example similar to this:

#div1 { position:absolute; left: 0px; width: 100px; border:solid 1px #000; }
#div2 { position:absolute; left: 100px; right: 100px; border:solid 1px #000; }
#div3 { position:absolute; right: 0px; width:100px; border:solid 1px #000; float:right; }

Answer №3

Here's a brain teaser for you all :)

<div class="maincontainer">
    <div class="column01">
        <div class="restraint">
            <p>Left column</p>
        </div>
    </div>
    <div class="column03">
        <div class="restraint">
            <p>Right column</p>
        </div>
    </div>
    <div class="column02">
        <div class="restraint">
            <p>Middle column</p>
        </div>
    </div>
</div>

and here is the corresponding CSS:

.maincontainer {
position:relative;
overflow:hidden;
}

.maincontainer .column01 {
float:left;
}

.maincontainer .column01 .restraint, .maincontainer .column03 .restraint {
width:200px;
}

.maincontainer .column03 {
float:right;
}

.maincontainer .column02 {
overflow:hidden;
}

.maincontainer .column02 .restraint {
width:100%;
}

* html .maincontainer .column02 {
display:inline-block;
}

Answer №4

I might face criticism for utilizing the <table> element, however, it remains one of the most versatile and compatible methods across different browsers. Surprisingly, it even functions in IE5!

Check out this example on jsFiddle

Answer №5

In this example, we demonstrate how to create a layout with three columns, two of which have fixed widths. Three columns: one takes up 100% and the other two have specific sizes.

JSFiddle Demo

CSS Styles

div, span, label, li, ul
{
    box-sizing: border-box;
    -ms-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
}

.header
{
    top:0px;
    left:0px;
    width:100%;
    height: 100px;
    display: table;
    position: absolute;
    border:1px solid orange; 
}
.row
{
    width:100%;
    display: table-row;
}

.left-column
{
    width:60px;
    height:100%;
    display: table-cell;
    white-space: nowrap;
    vertical-align: middle;

    border:1px solid black;
}
.left-column .icon
{
    width: 100%;
    text-align: center;

    border:1px solid red;
}

.center-column
{
    width: 100%;
    min-width:60px;
    text-align:center;
    display: table-cell;
    vertical-align: middle;

    border:1px solid black;
}
.right-column
{
    width:60px;
    height:100%;
    display: table-cell;
    white-space: nowrap;

    vertical-align: middle;

    border:1px solid black;
}
.right-column .logo
{
    width: 100%;
    text-align: center;

    border:1px solid red;
}

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

A guide to placing tooltips dynamically in highcharts column charts

I am encountering an issue with tooltips in Highcharts column charts. The problem arises when the series fill up my chart, causing the tooltip to be hidden below the series and cut off by the end of the div. You can see an example here: https://i.stack.i ...

I'm having trouble getting the "flex direction: row" property to work within a table row

First, I applied flex to the table > tr. Next, I configured the flex-direction to be row. table { width: 100%; } tr { display: flex; flex-direction: row; flex-wrap: wrap; overflow: hidden; width:100%; } td:nth-child(1) { flex: 0 0 20%; ...

Convert a web page with embedded images using Base64 strings into a PDF file using JavaScript

My website has numerous images with base 64 string sources. Typically, I am able to download the HTML page as a PDF using a service method that involves sending the HTML page with a JSON object and receiving the PDF in return. However, when there are many ...

issue arising where the table's border is not displaying

I'm confused about why the border of the first tbody tr's td is not visible. https://i.stack.imgur.com/Fwlv7.png I can't see any reason why the border is not showing up. Here's what I've figured out: If the natural height of th ...

What is the method to modify the text color of an <option> in a <select> tag?

I am attempting to change the color of only the text "select one option" to grey, but I am having trouble making it work. Here is my code: .grey_color { color: #ccc; font-size: 14px; } <select id="select"> <option selected="selected"> ...

Obtain consistent outcomes by entering identical data in both Ajax and PHP

My code takes a number input in a <textarea>, then uses AJAX to validate it randomly with PHP (using rand()). The validated number is returned along with the words correct or incorrect to a <div> in HTML. The issue is that if the same number i ...

Manipulate and scale with jQuery

I am currently utilizing the jQueryUI library with its Draggable and Resizable functionalities to resize and drag a div element. However, I am encountering some unexpected behavior where the div jumps outside of its container upon resizing. How can I resol ...

When the parent element is already set to justify its content with flexbox, you can ensure equal heights for CSS classes by utilizing

Within my design, I have several rows with 3 columns each. Every column contains a main content section labeled SavedSearchBox-content (with various permutations that affect its height) and a footer labeled SavedSearchBox-footer. To structure this layout, ...

I plan to add new information to my table only when the user clicks on the submit button. This is what I have accomplished until now

<!DOCTYPE html> <html> <head> <title>Sign up page</title> </head> <body> <form method="get" action="signup_redirect.php"> username: <input type="text" name="username" placeholder=" ...

Formatting a pair of elements side by side in MUI Select

Currently, I am tackling the challenge of organizing elements in MUI Select v4. My goal is to display these elements in two columns rather than just one column within the dropdown. Despite attempting to override certain styles within MUI, I have not been ...

Achieve a perfectly centered and responsive image placement on a webpage accompanied by a countdown timer

I've been trying to design an HTML page with a countdown feature, and I want to place an image above it that is centered and responsive. Despite my efforts, I haven't been able to achieve the desired responsiveness. I envision it looking like thi ...

Images in gallery slider are excessively large

Hello, this is my very first post on stackoverflow. Please forgive any atypical elements in this post. I have a Django Website with a gallery slider, but I am facing an issue where the images appear way too big. You can view them here: I have dedicated n ...

Skrollr immediate pop-up notification

Can anyone help me figure out how to make text appear suddenly and then disappear using skrollr? I've been able to get it to fade in and out, but I want it to just show up without any transition. Here's the code I have so far: <div id="style" ...

Share an image using only the publish_actions authorization

There are some apps I've come across that only request access to users_photos and publish_actions (not publish_stream or photo_upload). Surprisingly, they are able to upload photos without being approved for User Generated Photos (e.g. Instagram). Wh ...

jQuery Animated List - Nested items are unresponsive to clicks

Looking to create a dynamic nested list using jQuery for animations, but unsure of the best approach. Currently, I'm adjusting the length of the parent list item and revealing the nested items. The issue is that the parent item's length covers ...

Looking to create a pop-up using javascript, css, or jQuery?

When visiting digg.com and clicking the login button, a sleek in-screen popup appears to input user data. I'm curious about the best way to achieve this on my own site. It is built with RoR and includes some Javascript elements. Searching for "javasc ...

Tips for changing the background color of a Qtextedit?

After experimenting with HTML, I discovered that using type bgcolor="#ffd814" will change the background color in textedit. But how can I achieve the same result using QAction and QColorDialog? This is the method I tried: void MainWindow::on_actionBackgr ...

Python HTMLParser: Extracting HTML tag content made easy!

After working through an HTML page, I have now reached a point where I have lines that look like this: <td class="border">AAA</td><td class="border">BBB</td> I am trying to extract AAA and BBB into variables using HTMLParser, but ...

Creating Transparent Rounded Backgrounds in Google Chrome Packaged Apps: Achieving the same look as Google Hangout app

Looking at the screenshot below, it is evident that the Hangout app has a fully transparent design with background shadow effect applied to it. I have tried various methods in vain, such as applying CSS styling to the "html" and "body" tags of the page, a ...

The Navbar in Bootstrap 3 remains expanded and does not collapse

It seems like there's a simple solution I'm overlooking. When I resize my screen, the navbar collapse toggle stops working. I've searched various forums but couldn't find a fix that works for me. Could someone lend a hand in identifyin ...