Tips for adjusting the number of columns in a list display using CSS

Recently, I decided to delve into the world of CSS and Bootstrap. I came across an interesting example that I'm trying to implement in my project. You can find the example here.

Here's the HTML code snippet:

<div class="container">
    <div class="row">
        <div class="col-md-12 col-lg-6">
            <div class="card">
                <div class="header">
                    <h2><strong>New</strong> Friends <small>Add new friend in last month</small></h2>
                </div>
                <div class="body">
                    <ul class="new_friend_list list-unstyled row">
                        <li class="col-lg-4 col-md-2 col-sm-6 col-4">
                            <a href="">
                                <img src="https://bootdey.com/img/Content/avatar/avatar7.png" class="img-thumbnail" alt="User Image">
                                <h6 class="users_name">Jackson</h6>
                                <small class="join_date">Today</small>
                            </a>
                        </li>
                        ...
                    </ul>
                </div>
            </div>
        </div>
        ...
    </div>
</div>

And here's the CSS code snippet:

body{
    ...
}
.card {
    ...
}
...
a {
    ...
}

I'm looking to update the layout so that each row contains 5 data elements instead of 3. I've attempted using column-count but haven't had much luck. Any guidance on how to achieve this would be greatly appreciated!

Thank you!

Answer №1

This is my initial response (excited)

To begin, examine the html and locate the specific line of code. Replace col-lg-4 with col-lg-2 in every <li> element.

This adjustment only applies to larger screens

Original:

<li class="col-lg-4 col-md-2 col-sm-6 col-4"> <a href=""> <img src="https://bootdey.com/img/Content/avatar/avatar1.png" class="img-thumbnail" alt="User Image"><h6 class="users_name">Matthew</h6> <small class="join_date">17 Dec</small> </a></li>

Edited:

<li class="col-lg-2 col-md-2 col-sm-6 col-4"> <a href=""> <img src="https://bootdey.com/img/Content/avatar/avatar1.png" class="img-thumbnail" alt="User Image"><h6 class="users_name">Matthew</h6> <small class="join_date">17 Dec</small> </a></li>

For further clarification, refer to this page https://getbootstrap.com/docs/5.1/layout/grid/

Goodbye

Answer №2

To switch out the class col-lg-4, use the class .w-20 instead.

Next, in your CSS, include the class .w-20 like so:

.w-20 {
  -webkit-box-flex: 0;
      -ms-flex: 0 0 20%;
          flex: 0 0 20%;
  max-width: 20%;
}

For a more in-depth explanation, visit this link:

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

Updating style in Javascript can sometimes be a bit tricky

What's preventing this from working? localStorage.fontSize contains the correct value, but the initial document.body.style.fontSize = localStorage.fontSize + "pt"; doesn't update the style. <script type="text/javascript> if(!localStorage. ...

Locate the div element containing specific text and remove the text from the

Is there a way to locate a div that contains specific text and remove only that specific text from the div? For instance: <div> DeleteText <span>Something text</span> <div>Something span inner text </div> </div> I am l ...

How can you ensure that text in a container automatically moves to a new line and causes the container to expand downward if necessary, when

Are you searching for a way to make text inside a container wrap to a new line and have the container expand downwards if needed? Update <div class="modal hide fade" id="modalRemoveReserve" style="display:none;"> <div class="modal-header"&g ...

What is the best way to vertically center a button against a video using CSS?

How can I vertically center a button against a video using CSS? Here is my code: https://jsbin.com/curefoyefe/edit?html,css,js,output <video controls="" ng-show="myForm_live_video.live_video.$valid" ngf-src="live_video" width="200" height="200" class= ...

The gap separating the three columns in the DIVs structure

Here is an example that I need The images are being loaded from a MySQL while loop, and I want the spacing between them to be such that the left column and right column touch each side with the middle image centered. Just like in the picture :D This is m ...

Looking to utilize the <pre> tag without any external CSS styles defined in a separate stylesheet?

In my current project, I am using bootstreap v3.2. I am facing an issue where I need to display fetched content from the database on a page using the <pre></pre> tags. However, the problem is that the content is being displayed with the default ...

Arrange two columns of input fields vertically, one column with labels and the other without any labels

I am currently working on an application form for invoices, where I have set up five columns in one row. Each column contains input fields, with the fourth and fifth columns having four input fields each. However, the input fields in the fifth column do no ...

troubles arise when using undeclared functions in javascript

Recently, I've been working on implementing a Javascript CountDown Timer triggered by a button click. The Javascript code is stored in an external file, as well as the CSS for styling the timer. The problem arose when I tried including the Javascript ...

How can I send the input from a textbox to an email?

I'm looking to create a basic sign-up form where individuals can enter their email and submit it. The goal is to have this information sent via email to the site owner. I initially thought the code below would do the trick, but it doesn't seem t ...

Using a function on a singular element

I'm currently working on my portfolio and I would like to organize my projects in a menu similar to this felipestoker.com When you click on Works, it displays a menu with my projects categorized. However, when I click on a category, all of them appea ...

Is it possible to permanently alter HTML values with JavaScript?

Can a html value be permanently modified using javascript? I am trying to edit a local file. Below are the codes I'm using: function switchPic(){ top.topPage.activeDef = top.topPage.document.getElementById('h1'); top.topPage.activeDef. ...

What are the steps for implementing this javascript code in an HTML document?

Recently, I've been seeking advice on how to address the issue of wanting a button click to automatically select the search box on my website. Suggestions have pointed towards using Javascript for this functionality, with the following code recommend ...

Trying out basic form validation - Adjusting border color for an empty input

Currently, I am experimenting with a basic login form using PHP and testing it out on XAMPP in Chrome. Below is the code for the login form: <form action="login.php" method="POST"> <label>User: </label> <i ...

Show the cost on the HTML page according to the chosen currency option

I am currently dealing with two primary currencies in my business. The product page is created using HTML. There are 4 products on a single page, and I wish to display two prices for each product based on the selected currency (USD or EUR) without having t ...

Creating a Bootstrap 4 DIV element with horizontal scrolling functionality

I've been struggling to implement a horizontal scroll for a DIV on my site, but none of the common solutions like overflow-x or white-space:nowrap are working for me. This is the section of my website where I need a horizontal scroll bar If you want ...

The issue of CSS3 Grid-gap not functioning properly on iPhone devices

I've been working on creating a CSS template and everything seems to be functioning correctly, except for the grid gap which doesn't seem to work properly on my iPhone. Here's the code I have so far: <div class="grid"> <h1 ...

Unable to update div CSS using button click functionality

I have been working on this HTML/CSS code and I am trying to change the style of a div using a JavaScript button click event so that the div becomes visible and clickable. However, despite my efforts, it doesn't seem to be working as expected. Whenev ...

Banner with video background (not taking up the entire page)

I'm currently working on a website project that involves using a YouTube video as the banner, but I'm facing some challenges in making it work correctly. So far, this is what I have: #video-background { position: absolute; right: 0; top:1 ...

Angular 1.5 component using HTTP GET

Trying to utilize a 1.5 component with AngularJS has presented some challenges for me. I have a service that fetches my JSON file using $HTTP and returns a promise. In the controller of my component, I resolve the promise and assign it to a value using thi ...

Display/Conceal JavaScript

I recently implemented a JavaScript function on my website to show/hide specific elements. However, being new to JavaScript, I have encountered some difficulties. I've spent quite some time troubleshooting the code but haven't been able to pinpoi ...