"Utilizing CSS3 columns to create a layout with one column

I am looking to divide my webpage into multiple columns, starting with three but potentially adding more in the future.

My current approach involves using Flexbox to create equal-width columns:

<style>
.container {
    display: flex;
}

.column {
    flex: 1;

    /*for demo purposes only */
    background: #f2f2f2;
    /*border: 1px solid #e6e6e6;*/
    box-sizing: border-box;
    padding-left: 100px;
    padding-right: 100px;
    padding-top: 50px;
    text-align: center;
}

.column-one {
    order: 1;
}
.column-two {
    order: 2;
}
.column-three {
    order: 3;
}
</style>

Although this setup creates equally sized columns, I now want the second column to be smaller, occupying only 50% of the width.

I have attempted adjusting the width of the .column-two class, but without success. Is it feasible to achieve this customization within the existing code structure?

I appreciate the simplicity and flexibility of this design, as adding additional columns does not necessitate extensive CSS modifications. Hence, I aim to retain this framework for future enhancements.

Answer №1

       .container {
            display: flex;
            min-height: 200px;
        }

        .column {
            background: #f2f2f2;
            border: 1px solid black;
            margin: 3px;
        }

        .column-one {
            flex: 1;
        }
        .column-two {
            flex: 0.5;
        }
        .column-three {
            flex: 1;
        }
 <div class="container">
          <div class="column column-one"></div>
          <div class="column column-two"></div>
          <div class="column column-three"></div>
 </div>

In case you need to add a fourth column in the future, do the following:

                .column-one {
                    flex: 1;
                }
                .column-two {
                    flex: 0.5;
                }
                .column-three {
                    flex: 0.5;
                }
                .column-four {
                    flex: 1;
                }

Answer №2

When you set flex: 1 to column-two and flex: 2 to the other two columns in a flex container, column-two will be half or 50% width of the other two columns. It is worth noting that if you are not planning to change the order of the columns, there is no need to use the order property.

.container {
    display: flex;
    min-height: 100vh;
    flex-direction: row;
}

.column {
    /*for demomstration only */
    background: #f2f2f2;
    /*border: 1px solid #e6e6e6;*/
    box-sizing: border-box;
    padding-top: 50px;
    text-align: center;
    border: 1px solid black;
    margin: 5px;
}

.column-one {
    flex: 2;
}
.column-two {
    flex: 1;
}
.column-three {
    flex: 2;
}
<div class="container">
  <div class="column column-one"></div>
  <div class="column column-two"></div>
  <div class="column column-three"></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

Creating a typewriter animation using Tailwind CSS and Next.js

I am currently working on implementing a typewriter effect that is almost exactly how I want it. However, I am facing an issue with the printing process. Right now, each word gets printed on a new line and falls into place when done printing. What I actual ...

What is the best way to adjust the z-index when hovering over an li element

In my <ul>, each <li> contains an image. I want these images to scale and become opaque upon hover. However, the issue is that when they scale, they get covered by the following image. Unsure if the z-index is correctly placed... Below is the C ...

Guide to Hosting HTML on a Server Separate from Heroku

I currently have my index.html and the necessary .js files hosted on Heroku, where everything is functioning properly. However, I wish to avoid directing my users to "myappname.herokuapp.com", so I am considering using my own website to host the .html file ...

Animating a jQuery Knob as you scroll from 0 to a set value

I am new to jQuery and currently working on jQuery Knob. Everything is functioning properly, but I have encountered an issue. When scrolling to the section with the knobs, I would like them to animate from 0 to a specific value. Is there a way to achieve ...

Complete Form Validation Issue Unresolved by Jquery Validation Plugin

I'm facing an issue with the jQuery validation plugin while attempting to validate a form. Strangely, it only works for one input field. Can anyone suggest a solution? <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.valid ...

Converting Flex Text into HTML format for seamless integration

In my application, I have the capability to configure certain pages using the RichTextEditor and then save the resulting HTML Text Flow to a database for future use... When I import the saved data into Flex using a RichEditableText, everything appears as ...

Having difficulty setting a value for a tooltip with replaceWith() function

When using jQuery's .replaceWith() method to insert new DOM contents, I noticed that all content gets replaced except for the value of the title. Even though I tried different approaches, the tooltip only displays {{descriptions.title}} instead of the ...

What are some ways I can customize the appearance of a Bootstrap 5 Navbar specifically when it is in the collapsed

Currently utilizing Bootstrap 5, my goal is to align the Navbar social icons to the left when the navbar is collapsed for small/mobile devices, and to the right when viewed on a larger screen. Can you assist in identifying which selectors need styling for ...

What is the best way to add data-content to hr:after using JavaScript?

Adding style to an element in javascript can be simple. For example: myElement.style.color = "red"; However, what if I wanted to achieve something like this: hr:after { content: "myRuntimeValue" } Is there a way to do this using javascript? ...

What is the best way to add an image within a div without affecting the layout of the subsequent div?

I have created an HTML form with 4 inputs and a text area using bootstrap. I am looking to add an image to the right of two divs without pushing one of them down. I want it to look like the first image attached, but currently, it looks like the second ima ...

Issue with exchanging columns in Bootstrap version 5.0

Seeking assistance! I am a beginner with bootstrap and struggling to figure out an issue I'm experiencing. In the attached image(s), my goal is to have the coin image positioned above its corresponding text on the left side when the screen size is red ...

gallery showcasing pictures with a prominent main image and accompanying smaller images

I am struggling to display my image gallery the way I envision it. I would like to have a larger main image with the rest of the images displayed on the right side below it. The current code I have is: <div class="gallery"> <a href=" ...

Is it advisable to opt for window.webkitRequestAnimationFrame over setInterval?

Trying to figure out the best method for moving game characters in my JavaScript game - should I go with window.webkitRequestAnimationFrame or stick with setInterval? Any advice is appreciated! ...

Having trouble with Vue image source file paths?

Having an issue with loading an image via file_path on Vue. When using a hardcoded path, it works fine. Refer to the sample code below: JavaScript function getRestaurantsbyId(id) { var restaurants = { "1" : { "name": "xxxx", ...

HTML: Attempting to extract the inner div from the outer div and relocate it outside of the outer div

I am attempting to extract an inner div from an outer div and relocate it outside of the outer div. https://i.stack.imgur.com/NSS7B.png <div class="vc_gitem-zone-mini"> <div class="vc_gitem_row.............."></div> <div> I Would ...

Replace the hyperlink with plain text using JQuery

Is there a way to replace a hyperlink within an li element with different text but without removing the entire list item? <li class="pull-left"> <a href="#" class="js-close-post" data-post-id="1"> Close </a> </li> ...

Unable to remove the initial item from my shopping cart

Currently working on my computing science assignment and decided to create an online store. I followed a tutorial to implement the shopping cart functionality, but I'm facing an issue. I can delete every item in the cart except for the first one that ...

The radio button is not providing the necessary notification

I currently have the following elements on my webpage: Table rows that contain radio buttons A link labeled "Issue" that triggers a popup with one submit button A submit button labeled "details" that also triggers a popup The issue I am facing is as fol ...

Is there a way to align an element to the right of a centered element?

I am trying to center two inputs ("email" and "password") horizontally on the page. However, I also want to add another item to the right of them while keeping the inputs centered. <div style={{ display: "flex", justifyContent: "center" }}> < ...

Shopify revamping the design of the collections

Looking to enhance the layout of a collection page by moving from a single column to having at least three items per row. The current layout can be viewed here Proposed new layout example shown here 1: Below is a snippet of the code I believe needs adj ...