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?https://i.sstatic.net/o16Ju.jpg

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

Exploring the power of Vue.js by utilizing nested components within single file components

I have been attempting to implement nested single file components, but it's not working as expected. Below is a snippet of my main.js file : import Vue from 'vue' import BootstrapVue from "bootstrap-vue" import App from './App.vue&apos ...

Can you tell me the XPath of this specific element?

Looking for the XPath of this specific element: <a> href="/resident/register/">Register another device </a> I initially tried $x("//*[contains(@href, 'resident/register')]") Unfortunately, no results were returned. Any other su ...

The height of the textarea is too excessive

Just a quick question - in my HTML, I have a simple textarea nested within the body tags. Within my JavaScript, I am using jQuery to ensure that the body element is dynamically resized to match the height of the window: $(function() { $("body").heigh ...

Using Javascript's document.write function to modify the content of a PHP page

Here is a Javascript function that capitalizes the first letter of a string: function capitalizeFL(string) { return string.charAt(0).toUpperCase() + string.slice(1); } In a file named statuswindow.php, there are PHP scripts that use this function to ...

What is the direction of auto-filling in CSS grid?

Here's an unusual query that I've been pondering. Despite checking various CSS documentation, I haven't found a clear answer yet. Take a look at this: https://i.sstatic.net/SglOl.jpg It resembles something like this grid-template-columns: ...

Why Isn't AJAX Displaying the Output from PHP?

Currently, I am implementing ajax to display a string received from a php file. This particular php file is generating rows for an html table. My goal is to have ajax place these rows within a with a specific id that resides inside a and I want this oper ...

What is the best way to add bold formatting to text enclosed in parentheses using javascript/jquery?

How can I use jQuery or JavaScript to make the text inside parentheses bold? For example: "what is your Age (in Year)." I need assistance in making the text within parentheses bold using either jQuery or JavaScript. Can someone help me with this task? ...

I am interested in altering the color of table rows using either JQuery or CSS

Looking to update row colors based on grouping. For example: Color the TR accordingly for every 5 rows: First 5 rows in green (0-4 Rows), Next five rows in red (5-9 Rows), Following five rows in yellow (10-14 Rows) and repeat the pattern... ...

Having an issue with Local Storage returning undefined

I've been working on a form to input values and show the data on a different page after submission. Below is my form: <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" hr ...

When attempting to load a CSS file, Java automatically redirects to the login page

EDIT** After successfully loading CSS, I encountered an issue where the page kept redirecting back to login.jsp instead of displaying the CSS. Any insights on what might be causing this?https://i.sstatic.net/Ij7Oh.png I attempted to incorporate a custom ...

Tips for securely encrypting a PHP file when combining it with an HTML file using the phpB

I am attempting to encrypt a .php file using phpBolt. It works fine when the file contains only PHP code, but it fails when there is a mixture of HTML and PHP. Here is the encryption code: <?php /** * src : source folder * encrypted : Output folde ...

After refreshing the page, RouterLinkActive in Angular 6 fails to work

Scenario In my application, there is a menu with various items. The selected item is distinguished by adding the selected class to it, which changes its appearance. https://i.sstatic.net/JEPHH.png Problem While navigating between routes works smoothly, ...

How can you update the background image of a particular div using the 'onclick' feature in React.JS?

Thank you for helping me out here. I'm currently working with ReactJS and facing a challenge where I need to change the background of a div from a color to a specific image URL upon clicking a button in a modal. Despite my efforts, I keep encountering ...

How can I resize an element using jQuery resizable and then revert it back to its original size with a button click?

I need help figuring out how to revert an element back to its original size after it has been modified with .resizable. I attempted the following: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="//code. ...

Step-by-step tutorial on designing an input slider to dynamically adjust the CSS :before linear-gradient values

Is there a way to achieve a gradient effect using pseudo-element :before on an image that can be customized by adjusting a slider input? I've been trying to implement this feature with the following code, but have not been successful so far. var ...

Sorry, but we are experiencing difficulties processing your request at the moment. HTTP ERROR 500: We are unable to locate the

My code seems to be functioning correctly when connecting to the database, but I'm encountering an error. Here is the code snippet: <?php include 'header.php'; ?> <!DOCTYPE html> <html> <head> <t ...

Having trouble applying styles to a component using forwardRef

I'm relatively new to React and still trying to wrap my head around the component's lifecycle. However, the issue at hand is proving to be quite perplexing. One thing that confuses me is why adding "setState(10);" causes the style of the "Test" ...

Enable row selection in UI-Grid by clicking on a checkbox with AngularJS

I am a newcomer to angular js and I am looking to have the checkbox automatically selected when clicking on a row to edit that specific cell. I have implemented a cell template to display the checkbox in the UI-grid, but now, when I select a row, the row i ...

Attempting to squeeze a container with a set width into a parent element that spans the entire width of the screen (100

As I embark on my coding journey, I am faced with the challenge of creating a website that features full-width (100%) containers with fixed-width containers nested inside. Despite my efforts to experiment with both figures and divs, I have not been success ...

Utilize ng-checked in AngularJS to bind all values from an array to checkboxes

I'm working on a project where I need to bind the name and age of a person using checkboxes, with the data looped through ng-repeat. However, I seem to be able to only get the "name" from the array, not the "age". Can someone please help me find my mi ...