How can you properly line up three <div> elements?

My challenge involves arranging three <div> containers, positioned from left to right on the screen with equal spacing. However, I am seeking a method to align one container to the far left, another in the middle, and the third to the far right.

Is there a way to achieve this layout?

Answer №1

There are multiple ways to achieve this layout, whether using floats or table structure. A contentious debate exists between advocates of tables and proponents of floats. Personally, I tend slightly towards utilizing table layout, but each method has its own strengths. Below is an example focusing on the tabular approach:

<table style="table-layout:fixed;width:100%">
  <colgroup><col style="width:33%"/><col style="width:33%"/><col style="width:33%"/></colgroup>
  <tr>
    <td style="vertical-align:top">        
      <div style="border:1px solid red">
        column one with some lengthy text that needs to wrap while maintaining 33% width
      </div>
    </td>
    <td style="vertical-align:top">
      <div style="border:1px solid green">
        column two
      </div>
    </td>
    <td style="vertical-align:top">
      <div style="border:1px solid blue">
        column three
      </div>
    </td>
  </tr>
</table>

For a visual representation, refer to this link: http://jsbin.com/axojo

Answer №2

The 960 Grid System offers a strong and adaptable system for creating columns, whether fixed or fluid. It promotes a modular approach to styling, which aligns with my personal preference. I often customize the default output to better fit my needs.

For example, here is a setup with 3 columns:

Although there are numerous alternatives available, such as the Yahoo Grid Builder:

http://developer.yahoo.com/yui/grids/builder/

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

Using JS/PHP to send a POST request to a PHP script for querying a database

Trying to gather user input and then pass it to another PHP script for utilizing in a MariaDB query. Index.php: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="robots" content=&q ...

Switching the class from "untoggled" items to the selected item in React

Recently, I developed a toggle component known as Accordion. Within this component, I am iterating through an array of objects and displaying them in the following format: {object.map((o) => ( <Accordion key={o.id} title={o.question} className="i ...

Utilizing CSS to apply unique styles to individual radio buttons

I have 4 radio buttons in my quiz application. I need to style only one of them, which is the correct answer option. Here's the HTML snippet that was generated: <p> <input id="SelectedAnswer" type="radio" value="5" name="SelectedAnswer"> ...

What are the steps to modify the appearance of an input box in IE7 when it is in focus?

It's common knowledge that IE7 has its fair share of issues... I've scoured through countless posts here and on Google, all pointing me towards setting the style manually with onfocus() and onblur(). Alas, nothing seems to be working! This is t ...

Another CSS style is creating additional gaps within the div container

The code I'm working with currently looks like this: <div id="img_preview_text_container" style="width: 376px; height: 75px; top: 156px; left: 50px; color: rgb(255, 0, 0);"> <div id="customOnePreviewText" style="font-family: Oklahoma; ...

What is the procedure to modify a CSS class from the code-behind file?

So I have a CSS style in my .css class where the color is set to blue for hundreds of buttons. But now, my customer wants an option for green buttons which will be saved by a database field. So I check the field like this: if (!String.Is ...

Enhance your website design with a custom content scroller using Bootstrap and

Having trouble getting this plugin to work with bootstrap on my website. Does anyone have a solution for this issue? Alternatively, does anyone know of another approach I could take? UPDATE: I managed to fix the problem myself. Add the following code ...

Capturing the action phase in Liferay to change the cursor to 'waiting' mode

I'm currently working on a large Liferay project and have encountered a specific issue: Whenever something in the system is loading or processing, I need to change the cursor to a waiting GIF. While this is simple when using Ajax, there are many inst ...

A dynamic product showcase featuring a sliding table of different variations, created with HTML, jQuery, and CSS

Seeking assistance: Sample: http://jsfiddle.net/JQaLs/1/ How can I prevent the goods from moving downwards? Issue occurs when using: float:left; they start to move down. Apologies for my poor English. Update 1: When a good is clicked, the table sh ...

Calculate the pixel distance between various divs by measuring the horizontal distance from the left border to the right

I am trying to find the precise distance between : #main div left edge to the first div with class="b" between the first div with class="b" to the second div with class="b" It's worth noting that the divs may be arranged randomly and could have fix ...

Attempting to insert a square-shaped div within a larger square-shaped div and enable it to be moved around by dragging

Imagine this scenario: I have a button and a large div. When the button is clicked, the code adds a new div inside the larger one. However, the new div is not draggable because I didn't implement the necessary code. I'm also trying to figure out ...

Extract a specific pattern from a string using Javascript

Currently, I am attempting to extract a specific string from a tag in javascript using the following code: document.querySelector('.title h2').textContent However, when I execute this code, I am getting a result that includes unnecessary double ...

What could be causing my dropdown links to malfunction on the desktop version?

I've been developing a responsive website and encountering an issue. In desktop view, the icon on the far right (known as "dropdown-btn") is supposed to activate a dropdown menu with contact links. However, for some unknown reason, the links are not f ...

Preventing the generation of div tags with Thymeleaf's th:each functionality

<div class="question" th:each="question : ${questions}"> <h2 id="question" class="description" th:text="${question.description}">Question goes here</h2> <div id= ...

How can one manage styling choices in R Markdown while creating a PDF document?

Currently, I am utilizing R Markdown within the RStudio platform to produce documentation. When selecting the "Knit HTML" option, my output appears satisfactory. The ability to modify styling options and apply CSS Files directly is a beneficial feature. ...

Is there a way to divide my screen into four equal sections that expand when I hover over them?

Explaining the concept through visuals, I created mock-up images in MS Paint for reference. When the web page launches, it resembles this: https://i.sstatic.net/wzjDR.png Upon hovering over the top left corner, the square expands while the other three shr ...

<p> proper style can only be achieved with the addition of a background color</p

As I work on my mobile site, I am relying on CSS to ensure everything is as flexible and adaptable as possible. One issue that has been puzzling me is related to a <p> element within a div container. The goal is for the paragraph to span the entire ...

Issue with meta viewport on Android devices

Creating a versatile JavaScript dialog class is my current project using JQuery to generate centered div-popups on the screen. So far, implementation across common browsers has been straightforward. The challenge arises when dealing with mobile platforms ...

Contrasting onevent with addEventListener

After studying various DOM events, I attempted to implement the 'blur' event on the HTML body. My first attempt was with onblur document.body.onblur = () => { dosomething(); } and I also tried using AddEventListener document.body.addEven ...

What is the significance of using HttpUtility's HtmlDecode function in my code?

One of my ASP.NET MVC controllers returns a view where I generate some HTML code. For example: @Html.ActionLink(HttpUtility.HtmlDecode("&iquest;Olvid&oacute; su contrase&ntilde;a&#63;"), "ForgotYourPassword", "Account", null, new { style = ...