What guidelines should I establish for arranging 2 rows of .col?

I'm currently working on setting up two rows of .column elements in my HTML document. Right now, I have one row of columns followed by another row in the footer.

While the first row of columns is behaving as expected, the second row aligns vertically instead of horizontally. How can I adjust the CSS to make the second row function like the first?

Here is the HTML code snippet:

<div id="columns">
  <div class="left column">
    <p>left column</p>
  </div>

  <div class="middle column">
    <p>middle column.</p>
  </div>    

  <div class="right column">
    <p>right column.</p>
  </div>
</div>

<div class="footer">
  <div class="left column">
    <p>left column</p>
  </div>

  <div class="middle column">
    <p>middle column.</p>
  </div>    

  <div class="right column">
    <p>right column.</p>
  </div>
</div>

And here is the corresponding CSS:

#columns {
width: 960px;
padding-top: 50px;
margin-bottom: 0px;
}

#columns .column {
    position: relative;
    width: 300px;
    padding: 1%;
    border: solid 1px #000;
}

#columns .left {
    float: left;
}

#columns .middle {
    float: left;
}
#columns .right {
    float: right;
}
#container #col1 {
    width: 320px;
    float: left;
}

For a live example, check out this jsFiddle link.

Answer №1

Based on your query, it seems like you are looking to design a layout with three columns positioned side by side:

----------------------------------------------------------------
|     left column    |   middle column    |    right column    |
----------------------------------------------------------------
|     left column    |   middle column    |    right column    |
----------------------------------------------------------------

To achieve this layout, you don't need an overly complicated system as you have set up. You can actually accomplish the desired result with a simpler approach. Here's how you can do it:

<div id="container">

    <div class="column">left column</div>
    <div class="column">middle column</div>    
    <div class="column">right column</div>

    <div class="footer">
        <div class="column">left column</div>
        <div class="column">middle column</div>    
        <div class="column">right column</div>
    </div>

</div>​

Now for the CSS styling:

#container {
    width: 960px;  
    padding: 30px; 
    margin: 0;     
}

#container .column {
    border: solid 1px #000; 
    box-sizing: border-box; 
    float: left;            
    padding: 1%;            
    width: 300px;           
}

I have explained the significance of each element in the CSS code.

A crucial aspect here is the box-sizing: border-box; property. Without this, the borders and padding would add extra width to the columns, making them wider than intended. By using box-sizing: border-box;, the borders and padding fit within the specified width of each column.

In essence, three columns of 300px each total 900px. When combined with the 30px padding on each side within the #container, it stays within the 960px width of the container.

You can view all these implementations in action in my version of your fiddle

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

Is there a way to successfully press a button on a website?

While testing, I start by navigating in the constructor webBrowser1.ScriptErrorsSuppressed = true; webBrowser1.Navigate("http://www.tapuz.co.il/forums/forumpage/393"); webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted; Next, in the DocumentC ...

React Animation Library With Smooth Initial Render and No Dependency on External Props

I'm currently implementing a Modal component within my app, utilizing Portals. My goal is for the Modal to smoothly fade in when it is rendered and fade out when it is no longer displayed. Upon examining the documentation for react-transition-group, ...

A search form utilizing prepared statements in mysqli

Well met again, everyone. I recently reached out for help on improving some messy code I had put together, and the response was swift. Thank you for that! You can find the original question thread here: PHP - Search database and return results on the sam ...

Using CSS grid can allow for paragraphs to overlap on top of each

https://i.sstatic.net/LVsgQ.jpgCurrently working on constructing a biography page filled with text content, and I aim to utilize CSS GRID instead of floats. I encountered an issue in getting the text to occupy all the available white space within the layou ...

Triggering a click event within a Bootstrap popover

Clicking the inbox button triggers the inbox_open() function. When this function runs, three buttons appear in the inbox header but there is no onclick event listener attached to them. Make sure to review the code after the // inbox.open comment for critic ...

Having trouble setting the background of a div in CSS

How can I apply the background-color: #f8f8f8 class to the step class without interfering with the display of the horizontal lines after 1, 2? What could be causing this issue? .main-progress { text-align: center; position: relative; margin- ...

When using setInterval, the image remains static on Safari but updates on Chrome

In my project, I am using a mock array to distribute data. One part of the project utilizes this data to display a list of cases, each with assigned images. When a case is hovered over, the images associated with that case are displayed one at a time, with ...

React Div Element Not Extending to Web Page Margin

creating white space between the green div and both the top and sides of the screen This is my index page export default function Home() { return( <div className = {stylesMain.bodyDiv}> <div>home</div> &l ...

Incorporating a variable within a function in Javascript: A guide

Hey there, I'm facing a situation where I have a variable holding some data that needs to be included in a function. Let's say I have the following: var apikey="123456789"; function foo() { $.getJSON('http://api.websiteexample.com/ + a ...

Arranging Divs next to each other, ensuring uniform column heights, within a ContentPlaceHolder in ASP.NET

I am attempting to create a layout with three columns. The left and right columns will each contain a button that should remain aligned with the outer border of the container. In the center column, there will be an asp:Table generated dynamically, ranging ...

What is the appropriate way to include a line break in the title attribute within an HTML element?

I am currently utilizing the following code snippet: <a href="#" title="select from 1: this 2: that" > Click here </a> Whenever someone hovers over it, all the text is displayed on one line. Is there a method to display it on a new line inst ...

elements in suspension over non-suspended element:

I implemented a two column layout in my website, where one column is floated to the left and another is not: <div id="left"> LEFT </div> <div id="right"> RIGHT </div> Here is the CSS code for the layout: #left { floa ...

Troubleshooting problem with CSS borders in Microsoft Edge Browser

I am currently working on implementing the concept found at the following link: https://www.w3schools.com/howto/howto_js_tabs.asp, but with the additional feature of borders around the elements. However, I have encountered an issue specifically with Micro ...

Troubleshooting: Ngx-Echarts Animation Issue at Startup

I've been working on integrating ngx echarts into my Angular app, but I'm facing an issue with the animation during the initial load of the chart. Take a look at this Stackblitz example where you can see that the bars render quickly on initial lo ...

Manipulating the DOM in AngularJS Directives without relying on jQuery's help

Let's dive right in. Imagine this as my specific instruction: appDirectives.directive('myDirective', function () { return{ restrict: 'A', templateUrl: 'directives/template.html', link: functio ...

Trouble displaying portrait images in CSS slideshow

My portfolio includes an image slider called wow slider, which can be found at You can view my site with the image slider on this page: http://jackmurdock.site50.net/StudioWork.hmtl While most of the galleries display portrait and landscape images correc ...

Building a webpage that includes three div elements containing centered content, along with two additional elements to fill the remaining horizontal space

I am currently working on a CSS website and I want it to have three vertical divs: LEFT CENTER RIGHT. The content of the site will be in the center div, with the left and right divs filling the space between the center and the browser borders. Here is the ...

Utilizing Bootstrap 4 to ensure the final DIV is vertically stacked and fills the remaining space in the container

Having trouble creating a responsive layout using Bootstrap 4? Specifically, when two divs wrap vertically on smaller devices, the top div pushes the lower div down, exceeding the parent container. I want the lower div to fit within the container. How can ...

Display the Array Elements in HTML Format

I am attempting to iterate through a PHP array (found here) and display the data in an HTML list format. I specifically want to showcase the content and createdAt fields. This is the HTML structure I have envisioned, now I just need assistance with output ...

Is there a method to display text on the screen after a countdown has finished?

I am looking for a way to display some text or an image of a cake on the screen once this countdown reaches zero. It's a countdown leading up to my birthday, and I really want it to have that special touch at the end. However, I've been strugglin ...