Instructions on designing a three-column layout for six separate div elements

i am having trouble organizing 6 div elements into 3 columns per row. Currently, I have them arranged in two rows, but the issue arises when a column's h2 element is long and it pushes down the column below, creating a large space in the second row. Any suggestions on how to improve this alignment?

body {
    width: 100%;
    background-image: url("../img/pexels-photo-207301.jpeg");
    background-position: center center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-size: cover;
    background-attachment: fixed;

    font-family: "Abel", sans-serif;
    font-size: 20px;
    color: #3b3b3b;

}

h1, h2 {
    font-family: "'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif";
    font-weight: bold;
    text-transform: uppercase;
    margin: 0px;
    padding: 0px;
    color: #111111;
    text-align: center;
}

#mainpage {
    max-width: 960px;
    padding: 20px;
    margin: 0 auto;
}

#header {
    width: 100%;
    margin: 15px auto;
}

#logo h1 {
    line-height: 150px;
    letter-spacing: -1px;
    font-size: 4.5em;
}

#six-columns {
    width: 100%;
    background-color: rgba(250, 250, 250, 0.6);   
}


#six-columns .column {
    float: left;
    width: 29.333%;    
    margin: 1%;
    padding: 1%;  

}
#six-columns::after {
    content: "";
    display: block;
    clear: both;
}
    <body>
        <div id="mainpage">
            <div id="header-container">
                <div id="header">
                    <div id="logo">
                        <h1> My Third Site</h1>
                    </div>
                </div>
            </div>
            <div id="six-columns">
             <!-- Column Content Goes Here -->
            </div>
            <div id="test-floats">
                <h2> Testing Floats </h2>
            </div>
        </div>
    </body>

</html>

Answer №1

When using the float property, it is important to clear the left of the floating element. You can achieve this by adding the following CSS:

#six-columns .column:nth-child(4) {
    clear: left;
}

To learn more about the clear property, you can visit this link

body {
  width: 100%;
  background-image: url("../img/pexels-photo-207301.jpeg");
  background-position: center center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-size: cover;
  background-attachment: fixed;
  font-family: "Abel", sans-serif;
  font-size: 20px;
  color: #3b3b3b;
}

h1,
h2 {
  font-family: "'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif";
  font-weight: bold;
  text-transform: uppercase;
  margin: 0px;
  padding: 0px;
  color: #111111;
  text-align: center;
}

#mainpage {
  max-width: 960px;
  padding: 20px;
  margin: 0 auto;
}

#header {
  width: 100%;
  margin: 15px auto;
}

#logo h1 {
  line-height: 150px;
  letter-spacing: -1px;
  font-size: 4.5em;
}

#six-columns {
  width: 100%;
  background-color: rgba(250, 250, 250, 0.6);
}

#six-columns .column {
  float: left;
  width: 29.333%;
  margin: 1%;
  padding: 1%;
}

#six-columns::after {
  content: "";
  display: block;
  clear: both;
}

#six-columns .column:nth-child(4) {
  clear: left;
}
<div id="mainpage">
  <div id="header-container">
    <div id="header">
      <div id="logo">
        <h1> My Third Site</h1>
      </div>
    </div>
  </div>
  <div id="six-columns">
    <div class="column">
      <h2> Dignissim augue Dignissim augue</h2>
      <p>Dignissim augue aenean, fringilla maecenas. Consectetuer condimentum. Dis libero neque accumsan ipsum facilisi, neque ornare rem in ligula luctus. Elit quam tincidunt porta veniam lorem. Lobortis tempor vitae justo. Taciti suspendisse mauris, mattis
        a ligula velit semper pede euismod, tortor amet. Aliquam id, ut adipiscing. Morbi diam in neque, congue arcu elit maecenas, in sapien ullamcorper neque vestibulum. Leo nisl cursus turpis sit, vestibulum est ut tortor, massa hendrerit mauris orci,
        vestibulum in dolor eu penatibus</p>
    </div>

    <div class="column">
      <h2> cras tellus</h2>
      <p>Praesent nam tempus luctus vestibulum, vivamus wisi. Mauris vitae justo metus, pretium nulla eu proident morbi. Auctor vitae, felis dolor vel turpis diam. Cras morbi, duis a duis feugiat sodales ut cras, et sociis nibh tincidunt. Consequat nam nulla,
        interdum lectus rutrum ac penatibus mauris. Magna nisl arcu et platea a sed, cras tellus, sit nam turpis mi sodales pede nunc. Sapien donec facilisi cupiditate, suspendisse vel</p>
    </div>

    <div class="column">
      <h2> posuere erat</h2>
      <p>Lorem ipsum dolor sit amet, posuere erat quis tellus, pede non maecenas convallis dapibus ut, ipsum arcu facilisi nunc mollis eu risus, fermentum volutpat maecenas convallis etiam, et eget ut aliquet phasellus sagittis metus. Nulla vel wisi a eu
        in. Diam sociis eros. Aliquet vitae commodo ante, rutrum praesent odio urna pellentesque. Metus viverra volutpat etiam lorem nesciunt, sapien pellentesque, massa nec. Nec congue aliquam a lobortis sed, dui imperdiet vestibulum magnis aenean sed
        sit, dignissim sem sodales.</p>
    </div>

    <div class="column">
      <h2> nostra purus</h2>
      <p>Rhoncus ornare dictum varius suscipit nostra purus, sit sit egestas bibendum, pharetra quis ut magna integer wisi, orci purus sed sed dictum aliquam maecenas, pretium et urna porttitor integer fringilla at. Maecenas sapien. Nullam augue ac ut imperdiet
        sed mollis, duis vestibulum tellus nullam a enim, dui dapibus cras, quis justo mattis. Convallis non praesent quam elementum conubia, ante condimentum duis velit pharetra, lacinia ut molestie at justo etiam, metus tortor magna blandit sapien vehicula
        nullam, est posuere.</p>
    </div>

    <div class="column">
      <h2> suscipit nostra</h2>
      <p>Rhoncus ornare dictum varius suscipit nostra purus, sit sit egestas bibendum, pharetra quis ut magna integer wisi, orci purus sed sed dictum aliquam maecenas, pretium et urna porttitor integer fringilla at. Maecenas sapien. Nullam augue ac ut imperdiet
        sed mollis, duis vestibulum tellus nullam a enim, dui dapibus cras, quis justo mattis. Convallis non praesent quam elementum conubia, ante condimentum duis velit pharetra, lacinia ut molestie at justo etiam, metus tortor magna blandit sapien vehicula
        nullam, est posuere.</p>
    </div>

    <div class="column">
      <h2> Rhoncus ornare</h2>
      <p>Rhoncus ornare dictum varius suscipit nostra purus, sit sit egestas bibendum, pharetra quis ut magna integer wisi, orci purus sed sed dictum aliquam maecenas, pretium et urna porttitor integer fringilla at. Maecenas sapien. Nullam augue ac ut imperdiet
        sed mollis, duis vestibulum tellus nullam a enim, dui dapibus cras, quis justo mattis. Convallis non praesent quam elementum conubia, ante condimentum duis velit pharetra, lacinia ut molestie at justo etiam, metus tortor magna blandit sapien vehicula
        nullam, est posuere.</p>
    </div>
  </div>
  <div id="test-floats">
    <h2> Testing Floats </h2>
  </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

The HTML div captured with html2canvas is incomplete

I am currently developing a meme editor website utilizing the html2canvas library available at Below is the HTML code for the div I aim to capture: <div class="container"> <div id="theUserMeme"> <div class=& ...

Center Button Horizontally and Vertically with CSS Code

I really need some assistance with getting this button I made to be perfectly centered on both the vertical and horizontal axes of the page. So far, I've managed to center it horizontally, but not vertically. Any advice or guidance would be greatly ap ...

Two elements failing to display side by side

Can someone help me figure out how to align the quantity and Add-to-cart button on the same line? The quantity is displaying as a block element even though I set it as inline... any suggestions would be appreciated! Visit this link for reference. I' ...

Unable to modify the width of textarea

I've been struggling to adjust the width of a textarea element, as neither setting rows and cols in HTML nor using CSS has worked for me. The height adjustment was successful with HTML. Any tips on changing the width? form, label { position: rel ...

Issue with CSS styling on a content slider causing the last picture to display incorrectly

I recently updated a Content Slider and tweaked the styles to my preference. Check out the changes I made on this link. In addition, I included an extra Thumbnail Picture on the right (7th one) along with the Main Picture. Oddly enough, the Slider seems ...

What is the rationale behind transmitting JSON data within HTML in Next.js's static site generation (

When a webpage is loading, the entire HTML document is sent, whereas in client-side routing, only the JSON file and JS chunk are sent. But why does the HTML file filled with data need to contain JSON data too? Is it really necessary since we already have ...

Developing an Easy-to-Use PDF Popup Interface

I need a simple PDF modal where I can input the text: 'The sky is blue' and have it link to a PDF that opens up when clicked. I found a similar sample online, but it includes an image plus an image modal that pops up. I want to replace the imag ...

I am having difficulty organizing my text into two grid columns and aligning it in the center

.hero { display: grid; grid-template-columns: repeat(2, 33.45rem); grid-template-rows: 12.5rem; border-bottom: .05em solid #05d31f; width: 69.8rem; height: 16.5rem; } .hero-title { grid-row-start: 1; grid-column-start: 1; } .hero-title h ...

The image selection triggers the appearance of an icon

In my current project, I am working on implementing an icon that appears when selecting an image. The icon is currently positioned next to the beige image, but I am facing difficulties in making it disappear when no image is selected. Below are some image ...

Vuetify - Best practices for vertically aligning rows in a v-treeview component

Just getting started with Vue js, so pardon me if this is a silly question. I've scoured the internet and can't seem to find a solution. I'm working on a v-treeview displaying a folder structure, with descriptions of each folder in a separa ...

Maintaining the image's aspect ratio using the Next Image component

Currently, I am using Next's Image component to display a logo. Although the image itself is 1843x550 px, I have specified the width and height properties to adjust it to fit within a space of 83x24 px. However, due to a slightly different aspect rati ...

What is the best way to incorporate a splatter image within an MDX blog post?

I am working on an MDX blog where I render a blog post. pages/index.tsx <main className="flex min-h-screen dark:bg-black"> <div className="wrapper mb-24 gap-8 px-8 lg:grid lg:grid-cols-[1fr,70px,min(70ch,calc(100%-64 ...

Tips for dividing echo output from PHP into two separate divs using jQuery AJAX

I am trying to display two different echoes from PHP in separate divs within my AJAX success function. $.ajax({ url: 'counter.php', type: 'POST', data: { some_data:some_data ...

What is the method for choosing an Object that includes an Array within its constructor?

Is there a way to retrieve a specific argument in an Object constructor that is an Array and select an index within the array for a calculation (totaling all items for that customer). I have been attempting to access the price value in the Items Object an ...

JavaScript popup cannot be shown at this time

I'm encountering an issue with displaying popups using JavaScript. Currently, only the div with class "popup" is being shown. When a user takes action, both popup and popup2 should be displayed but for some reason, it's not working as expected. ...

Is utilizing unregistered HTML elements for semantic purposes considered poor practice?

When it comes to styling and semantic purposes, I am considering using unregistered web components. This means utilizing tags like <t-card></t-card> without registering them with customElements.define. Surprisingly, the browser and stylesheets ...

access denied on image links

While developing a web app with Angular5, I encountered an issue regarding retrieving image URLs from the 4chan API. Each post in my database contains an image URL, however, when I try to access it through my app, I receive a 403 forbidden error in the con ...

Calculating values within dynamically generated elements requires utilizing JavaScript to target and extract the

I am working on creating input fields inside an HTML table using Vue.js. On click of a button, I want to perform some calculations based on the input values. However, it seems that the calculations are not happening as desired. What I have attempted so fa ...

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 = ...

Having difficulty in getting a hyperlink to open in a new tab with _blank attribute

I'm currently working with this code for my link. <a href="https://dribbble.com/jamesfrewin"><img class="socialicon" src="images/icons/dribbble_dark.png" onmouseover="this.src='images/icons/dribbble_pink.png'" onmouseout="this.src= ...