What is the best method for transforming this table design into a div structure?

After being told by a friend to try using the div layout, I've been struggling to make it work for my needs.

My goal is to achieve the layout shown in the diagram below:

+-----------------------------------------+
|           Fixed Height = 50             |
+-----------------------------------------+
|         |                  |            |
|         |                  |            |
|  Fixed  |     Whatever     |    Fixed   |
|  Width  |     Remains      |    Width   | Total Height = 500px
|    =    |      In All      |      =     | Total Width  = 600px
|   150   |    Directions    |     150    |
|         |                  |            |
|         |                  |            |
|         |                  |            |                    
+-----------------------------------------+
|           Fixed Height = 50             |
+-----------------------------------------+

The desired transformation is from http://jsfiddle.net/qPgVx/ . to http://jsfiddle.net/blineberry/juckh/7/ (utilizing divs instead).

This customization is essential because the entire form needs to be adjustable with JavaScript and the center part should flexibly expand and contract.

Unfortunately, I'm facing an issue where the middle section doesn't fill up the height. How can I resolve this?

Answer №1

Take a look at: http://jsfiddle.net/thirtydot/kBHCR/

By adjusting the width and height of .Window, you can see that everything resizes accordingly.

This method is compatible with IE7+ and all modern browsers.

However, it is important to note that this approach does not work in IE6. If IE6 support is required, alternatives like using JavaScript specifically for IE6 or sticking with a <table> may be necessary. But keep in mind, supporting IE6 may come with its challenges.

CSS Styles:

.Window {
    width: 600px;
    height: 500px; 
    background-color: rgb(0,0,0); 
    position: relative;
}
.Window-Top {
    height: 50px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background-color: rgb(128,128,128); 
    background-image: -webkit-linear-gradient(bottom, rgb(167,167,167) 25%, rgb(208,208,208) 78%);
    background-image: -moz-linear-gradient(bottom, rgb(167,167,167) 25%, rgb(208,208,208) 78%);
    background-image: -o-linear-gradient(bottom, rgb(167,167,167) 25%, rgb(208,208,208) 78%);
    background-image: -ms-linear-gradient(bottom, rgb(167,167,167) 25%, rgb(208,208,208) 78%);
}
.Window-Bottom {
    height: 50px;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgb(0,128,128);
}
.Window-Content {
    position: absolute;
    top: 50px;
    bottom: 50px;
    left: 0;
    right: 0;
}
.Window-Content-Left {
    width: 150px;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    background-color: rgb(255,0,0);
}
.Window-Content-Right {
    width: 150px;
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    background-color: rgb(0,0,255);
}
.Window-Content-Content {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 150px;
    right: 150px;
    background-color: rgb(0,255,0);
}

Answer №2

A friend of mine recommended using the div layout, but I'm having trouble getting it to work.

Let's address the myth that "Tables are evil." In reality, if a table works well for your needs, there's no need to switch to a different layout.

However, I am struggling to make the div layout function properly.

It's true that simulating a table with divs can be challenging. Those advocating against tables should provide simpler and more reliable alternatives using CSS. While CSS is powerful, achieving equal heights for multiple elements without JavaScript is not straightforward.

If you're determined to give it a try (which I recommend for learning purposes), look up "css multi-column layout" on the internet to better understand the limitations of CSS.

For starters, read this informative article: Multi-Column Layouts Climb Out of the Box

Answer №4

Opt for floating divs to position the middle three divs.

.Panel-Left {   
  ... 
  float:left;
  ...
}

.Panel-Right {   
  ... 
  float:right;
  ...
}

Remember to clear the floats when necessary:

clear: both;

Answer №5

For more information, you can check out this link or this one.
In essence, they utilize margins on the central <div> and then position the sidebars within the margins while ensuring they appear to be of the same height.

If you want to see an example in action, take a look at this jsfiddle

Answer №6

To achieve a fixed dimension layout, you can implement the following approach:

http://jsfiddle.net/qPgVx/9/

The key is to float the three middle divs and complement them with another div using clear:both for proper alignment. For more detailed information, refer to this link.

UPDATE: If you require a liquid layout, consider exploring this example:

http://www.alistapart.com/d/negativemargins/ex5.htm

This resource from the article discusses innovative solutions:

http://www.alistapart.com/articles/negativemargins/

An issue often faced is the middle column not extending to full height, resolved using "faux columns" technique. It involves utilizing background images or wrapper divs to mimic the middle column's background color. Further insights on faux columns can be found here:

http://www.alistapart.com/articles/fauxcolumns/

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

The "(click)" event doesn't fire upon clicking a material icon

After creating an <a> tag with a (click) event function call, I noticed that the click event works everywhere except for the arrows mat-icons within the code snippet below: <span *ngIf="section.pages.length>0"> <mat-icon *ngIf="secti ...

Difficulty encountered in positioning a div element

I have been attempting to align the div with class bioDiv under the image, but despite various attempts, I find myself feeling more and more confused. Can someone please review the code for me and offer a clue? I want to retain the same appearance, just re ...

Utilizing the "::first-letter" pseudo element selector in conjunction with the MuiButton class in Material UI - What is the process?

Is it possible to change the text case of Button text inside Material UI Button to sentence case with CSS? https://mui.com/components/buttons/ The text inside the button - ADD FRIEND should be transformed to sentence case as Add friend. I attempted to o ...

Ways to align two buttons side by side in HTML

I'm struggling with the code on my company's website. I can't seem to get the buttons to float properly with the given code. <div class="text-center"><a class="text-center" href="/contact-us"><button class="btn btn-small btn- ...

Utilizing box-sizing for the creation of an internal border

Looking to create an HTML table with clickable cells, each containing a div that adds a border upon clicking. The challenge is ensuring the border stays within the boundaries of the td without altering the size of the table or its cells. Struggling to achi ...

Footer disappearing on iPad Safari viewing

I'm currently facing an issue with the footer on a website I'm working on. Everything is working fine except for when the site is viewed on Safari on an iPad. The footer is appearing way above the bottom of the page and after spending an hour try ...

I have a vision of creating a unique Countdown Stopwatch that meets all my

I'm looking to create a custom countdown stopwatch where I can set the time and watch it count down to 0:00. The stopwatch should have three buttons: Start, Stop, and Reset. I've searched multiple websites for what I need but haven't found ...

Is there a way to prevent Bootstrap offcanvas from causing the website to scroll?

Utilizing a Bootstrap offcanvas for a <nav> menu on a mobile site, I aim to navigate users to specific sections of the website when they click on a <li>. I've implemented a simple JavaScript script that triggers the offcanvas exit button a ...

Looking for assistance with arranging Divs in HTML?

Having trouble getting my colored div boxes aligned side by side. The lower two divs seem to be overlapping with the yellow div on top of the blue one. How can I fix this and get them to line up like the green and red divs? Could it be an issue with how I& ...

The new version 5.1 of Bootstrap modal does not disable scrolling on the <body> element

I'm currently working on a project in Angular 11 using Bootstrap (v5.1.3). My main goal is to create a functionality where clicking on a card, similar to a blog post, will trigger a Bootstrap modal popup displaying the content of that specific post. B ...

Tips on concealing JavaScript values from being detected during web inspection

I need to securely pass a secret code from my backend to the front end and store it in my JavaScript script. Here is an example of how I want to achieve this: <script> var code = '<%= code %>' </script> Once the us ...

creating a responsive form with angular flex layout

We are currently utilizing the following library: https://github.com/angular/flex-layout Our current code for achieving fxlayout is as follows, however, it is not functioning correctly on mobile devices. <div fxLayout="column" id="width& ...

I encounter internal server errors when trying to upload images in React

Attempting to send a post request with an image, but encountering errors without understanding why.https://i.sstatic.net/W5uk1.png const [image, setImage] = useState([]); const handleImage = (event) => { setImage(...Array(event.target.files ...

Fully conceal a DIV while the webpage is loading

Following the header, I've implemented a hidden div with a height transition that can be activated by a button. However, there seems to be an issue where the browser displays the content of the div while the page is loading and then hides it afterward ...

The user uploads an image to the server, which is then assigned as the background-image for a div element

I am in search of a straightforward method to allow users to upload an image to my server and then use that uploaded image as the background-image for a div element. I need the image to be actually uploaded to the server rather than just displaying a local ...

Loading a link within a Vue.js component is a seamless process

Looking to incorporate an external URL into my Vue Application while keeping the Toolbar and Sidebar intact within a component. Any suggestions on how I can achieve this? Thanks in advance ...

Utilizing ngx-bootstrap Modal for Data Transfer to Component

I am currently dealing with an array called drivers in my component. When a button is clicked in the component, it triggers a ngx-bootstrap modal to display the fullname value from the drivers array. Now, I am looking for a way to retrieve the selected nam ...

Set the input of a component in Angular to determine its width

I am working on a basic angular component. Here is the code snippet: <div class="k-v-c" fxFlex fxLayout = "row" > <div class="k-c" fxFlex = "widthOfTable" > {{ key | translate }} </div> < div class="separator" > ...

Setting up a global CSS and SASS stylesheet for webpack, TypeScript, Phaser, and Angular: A step-by-step guide

A manual configuration has been set up to accommodate all the technologies mentioned in the title (webpack, typescript, phaser, and angular). While it works perfectly for angular component stylesheets, there seems to be an issue with including a global st ...

Executing a function within a ng-repeat iteration

Is there a way to call a method within an ng-repeat loop, even if the element does not exist at that moment? I'm facing this issue and I'm not sure how to resolve it... The ID seems to be correct. Strangely, when I run it in the console after ev ...