Attempting to create a webpage layout featuring three distinct columns, each showcasing unique content, all without relying on traditional table elements in CSS and

After numerous attempts, I am uncertain if this can be accomplished.

I am trying to create an HTML page with 3 columns, each containing different elements. Despite trying various methods, I am stuck and unsure if this layout can only be achieved using a table.

Is there a way to structure the columns as shown in the sample grid below without altering the HTML code, but only utilizing CSS?

Desired Layout:

----------------------------------------------------
| Column left 1|   Column center   | Column right  |
---------------|                   |----------------
| Column left 2|                   |
---------------|                   |
| Column left 3|                   |
---------------|                   |
               |-------------------|

Current Output:

----------------------------------------------------
| Column left 1|   Column left 2   | Column left 3 |
---------------|-------------------|----------------
-------------------------------------
|   Column center   | Column right  |
|                   |----------------
|                   |
|                   |
|                   |
|                   |
|-------------------|

Below is the code for my recent attempt...

    * {
      box-sizing: border-box;
    }

    .column {
      float: left;
      width: 33.33%;
      padding: 10px;
      height: 200px; /* Should be removed. Only for demonstration */
    }

    .row:after {
      content: "";
      display: table;
      clear: both;
    }
    <h2>Three Columns</h2>

    <div class="row">
    <div>
      <div class="column" style="background-color:#aaa;">
        <h2>Column 1</h2>
        <p>Some text..</p>
      </div>
      <div class="column" style="background-color:#aaa;">
        <h2>Column 1 a</h2>
        <p>Some text..</p>
      </div>
      <div class="column" style="background-color:#bbb;">
        <h2>Column 1 b</h2>
        <p>Some text..</p>
      </div>
    </div>
      <div class="column" style="background-color:#bbb;height: 650px">
        <h2>Column 2</h2>
        <p>Some text..</p>
      </div>
      <div class="column" style="background-color:#ccc;">
        <h2>Column 3</h2>
        <p>Some text..</p>
      </div>
  </div>

Any assistance or recommendations would be greatly valued. Thank you in advance.

Answer №1

If you're only looking to make changes in CSS, I recommend using the "display: flex" property. In my view, it's the optimal choice. For more information on this topic, check out my preferred resource.

* {
  box-sizing: border-box;
}

.column {
  padding: 10px;
  margin: 5px;
}

.row:after {
  content: "";
  display: table;
  clear: both;
}

.row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
}

.row div {
  display: flex;
  flex-direction: column;
}

I trust that this suggestion will be beneficial and effective for your needs.

Answer №2

If you want more control over how your containers are set up, consider using display: flex;. You can also fine-tune the spacing between elements by adjusting the padding.

.row {
  display: flex;
}
.column {
  flex: 1;
}
.col-1-cont {
  padding: 1rem;
}
    <h2>Three Columns</h2>

    <div class="row">
    <div class="column" id="column-1">
      <div class="col-1-cont" style="background-color:#aaa;">
        <h2>Column 1</h2>
        <p>Some text..</p>
      </div>
      <div class="col-1-cont" style="background-color:#aaa;">
        <h2>Column 1 a</h2>
        <p>Some text..</p>
      </div>
      <div class="col-1-cont" style="background-color:#bbb;">
        <h2>Column 1 b</h2>
        <p>Some text..</p>
      </div>
    </div>
      <div class="column" style="background-color:#bbb;height: 650px">
        <h2>Column 2</h2>
        <p>Some text..</p>
      </div>
      <div class="column" style="background-color:#ccc; height: 200px;">
        <h2>Column 3</h2>
        <p>Some text..</p>
      </div>
  </div>

Answer №3

It seems like the column class is being incorrectly applied to certain elements. The wrapper of the left column should be set as a column by using the column class, but it appears to just be a normal div (block element with 100% width).

To fix this issue, try restructuring your code as follows:

   * {
      box-sizing: border-box;
    }

    .column {
      float: left;
      width: 33.33%;
      padding: 10px;
      height: 200px; /* This should be removed, as it's only for demonstration purposes */
    }

    .row:after {
      content: "";
      display: table;
      clear: both;
    }
<h2>Three Columns</h2>
    
        <div class="row">
        <div class="column"><!-- This is the wrapper that creates the column and should occupy 33% of the width -->
          <div style="background-color:#aaa;">  <!-- These columns should fill the total width within the 33% column wrapper, defining their individual widths -->
            <h2>Column 1</h2>
            <p>Some text..</p>
          </div>
          <div style="background-color:#aaa;">
            <h2>Column 1 a</h2>
            <p>Some text..</p>
          </div>
          <div style="background-color:#bbb;">
            <h2>Column 1 b</h2>
            <p>Some text..</p>
          </div>
        </div>
          <div class="column" style="background-color:#bbb;height: 650px">
            <h2>Column 2</h2>
            <p>Some text..</p>
          </div>
          <div class="column" style="background-color:#ccc;">
            <h2>Column 3</h2>
            <p>Some text..</p>
          </div>
      </div>

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

Attempting to eliminate the parent container of a slide generated by the Slick Slider Plugin

I have developed a filter mechanism that hides specific classes within a slick slider based on the data-tag associated with the objects and the value of checkboxes. However, when these classes are hidden, they still occupy space because I should be hiding ...

I keep encountering an Uncaught TypeError when trying to read the property 'options' of null, despite having the element ID properly defined

I am a newcomer to the world of Javascript and HTML. Despite having the element defined in HTML, I am encountering an exception. Could someone please offer assistance? My goal is to create a shape (initially a circle) based on user input such as shape type ...

Tips on updating the default checkbox dynamically based on the current checkbox using JavaScript

Seeking to enhance the design of a Perl-generated form with custom CSS effects, rather than relying on the default Perl form. Despite successful functionality, encountering an issue where radio button focus reverts to default selection (Date) after submitt ...

What could be preventing my XPath from selecting a link/button using its label text?

<a href="javascript:void(0)" title="home"> <span class="menu_icon">Possibly more content could go here</span> Home </a> When I use //a as the XPath in the above code, it is highlighted. However, when I try //a[contains(text ...

Toggle sliding in an open or closed direction indefinitely

Currently facing an issue where a menu should open/close on mobile devices. To achieve this, I have implemented an if-statement to check the browser width and execute a script accordingly: $(window).resize(function() { var mobilewidth = $(window).width( ...

Guide to scraping data from a table using Python and BeautifulSoup

I'm looking to extract information from the caranddriver.com website through web scraping. Specifically, I need to retrieve the trim lines and prices from a table. Since I am just starting out with coding, any input you can provide would be greatly a ...

Tips for aligning a div within a flexbox to the bottom position

I'm having trouble aligning the div at the bottom of the flex box. I attempted to use align-content: flex-end; but it didn't work. Is there a way to keep the <.div class="parameters"> at the bottom of the row? Especially when the ...

Creating an Active Link in Django Template

I am working with a form in Django and facing a challenge of dynamically adding the correct ID at the end of the URL. I need to figure out how to do this efficiently. Below is an example code snippet: {% for dealer_payment_account in dealer.dealerpaymentac ...

Is there a way to deactivate tabs in Bootstrap?

Is there a way to deactivate tabs in Bootstrap 2.0 similar to how you can disable buttons? ...

Utilizing PHP Code within Inline CSS in HTML guides

Is it possible to integrate PHP code into Inline CSS? Here is an example: Check out this code snippet: <div class="col-auto"> <div class="h5 mb-0 mr-3 font-weight-bold text-gray-800">%22</div> </div> <div ...

Enhance the functionality of jQueryUI sortable by enabling scrolling and incorporating a delay specifically for mobile

I have an inline thumbnail gallery that can be sorted using jQueryUI and the touch punch plugin for mobile devices. Everything is functioning correctly, except on mobile devices with a large number of images. I am unable to scroll down the screen to view ...

Loop through items in a list using Angular.js and display each item within an <

I am facing an issue where the model returned from the server contains html tags instead of plain text, such as b tag or i tag. When I use ng-repeat to create a list based on this model, the html is displayed as pure text. Is there a filter or directive av ...

Design concept - Trigger an action upon clicking a checkbox within a table row

I've been working on implementing a selectable table using material design. I want to trigger an action when a checkbox in a table row is clicked, but my attempts with jQuery have not been successful. Here's the structure of my table: <table ...

Elements floating in space, stretching across the entire width

In my design, I have a fixed size layout with a centered content container. My goal is to have the menu (home, about, contact, login) span 100% of the screen width. You can view the current setup in this jsfiddle: http://jsfiddle.net/Hxhc5/1/ I am aimin ...

Implementing Google Fonts into Next.js with the combination of Sass, CSS, and Semantic UI React

I have set up my next.config.js file with the following configuration: const withSass = require('@zeit/next-sass'); const withCss = require('@zeit/next-css'); module.exports = withSass(withCss({ webpack (config) { config.module. ...

Setting a variable equal to user input

When using a jQuery script, the elements for the details are dynamically created inside a jQuery function. However, there seems to be an issue with assigning the value from the variable "startLocation" to the input "detail_startLocation[]". Only the firs ...

Preventing the inclusion of current URL in the URL input

I have a situation where I need to print custom URLs in the footer that are retrieved from a database. For example, let's say the URL is www.google.com. <li><a href="<?php echo $links['link_url']?>"><?php echo $links[&a ...

Display the div only when certain other divs have been clicked

I am fairly new to jQuery (this is my second attempt at using it). I have searched for solutions on Google and StackOverflow, tried several approaches, but still can't solve the last part of my issue. Any assistance or direction would be greatly appre ...

Having Numerous HTML Tables All in One Page Accompanied by Written Content

I used to have a webpage with multiple (4) HTML tables all contained within one div that spanned the entire page, serving only as an indicator for the tables' starting point. It all worked perfectly until a recent Chrome update caused chaos with the t ...

Introduction beneath the photograph using the Bootstrap framework

I have a div with an SVG background image and I am attempting to override Bootstrap's responsive behavior so that content can be displayed over the background. The desired outcome is for the text "test" to appear on top of the background, rather than ...