Can the design be implemented using the Bootstrap grid system?

Utilizing bootstrap 5, yet a bootstrap 4 demonstration may suffice.

Clearly, I can accomplish this design without employing bootstrap, however, that is not my current objective. I am curious if there is a feature within the bootstrap framework that I may be overlooking.

Initially, here is a snapshot of what I am aiming to achieve.

https://i.sstatic.net/gBvhE.png

Specifications of the layout:

  • Container width: 1440px
  • Grid gutter width: 32px
  • 14 column layout

Each attempt poses its individual challenge:

1st attempt(refer to code below) and the issue: Orphans(last row) are centered instead of left-aligned.

2nd attempt(refer to code below): The parent (now the 12 column layout) is too narrow, hence the columns do not possess the required 370px width.

3rd attempt(refer to code below): Not suitable for wrapping columns(obviously).

1st attempt code:

    <div class="container">
        <div class="row justify-content-center">
            <div class="col-14 col-md-7 col-lg-4"></div>
            <div class="col-14 col-md-7 col-lg-4"></div>
            <div class="col-14 col-md-7 col-lg-4"></div>
            <div class="col-14 col-md-7 col-lg-4"></div>
        </div>
    </div>

2nd attempt code:

    <div class="container">
        <div class="row justify-content-center">
            <div class="col-14 col-lg-12">
                <div class="row">
                    <div class="col-14 col-md-7 col-lg-4"></div>
                    <div class="col-14 col-md-7 col-lg-4"></div>
                    <div class="col-14 col-md-7 col-lg-4"></div>
                </div>
            </div>
        </div>
    </div>

3rd attempt code:

    <div class="container">
        <div class="row justify-content-center">
            <div class="col-14 d-none d-xl-block col-xl-1"></div>
            <div class="col-14 col-md-7 col-lg-4"></div>
            <div class="col-14 col-md-7 col-lg-4"></div>
            <div class="col-14 col-md-7 col-lg-4"></div>
            <div class="col-14 col-md-7 col-lg-4"></div>
            <div class="col-14 d-none d-xl-block col-xl-1"></div>
        </div>
    </div>

Once again, solely seeking bootstrap solutions. I am capable of achieving this without bootstrap, but I am exploring potential overlooked features.

Answer №1

Using responsive breakpoints while seeking specific pixel widths may seem contradictory. However, by utilizing a nested layout and applying me-auto (margin-right: auto), you can align the orphaned columns to the left.

<div class="container">
    <div class="row">
        <div class="col-md-1 border"><!--spacer--></div>
        <div class="col-md">
            <div class="row justify-content-center border">
                <div class="col-14 col-md-7 col-lg-4">
                    <div class="border">col</div>
                </div>
                <div class="col-14 col-md-7 col-lg-4">
                    <div class="border">col</div>
                </div>
                <div class="col-14 col-md-7 col-lg-4">
                    <div class="border">col</div>
                </div>
                <div class="col-14 col-md-7 col-lg-4 me-lg-auto me-0">
                    <div class="border">col</div>
                </div>
            </div>
        </div>
        <div class="col-md-1 border"><!--spacer--></div>
    </div>
</div>

UPDATE: The use of auto margin may cause the column to be offset too much to the left, as 14 columns do not evenly divide by 3. Hence, achieving the desired layout with 14 columns may not be feasible.

Answer №2

Bootstrap suggests that for centering columns on a web page, you should use the parent class .container followed by .row and then specify the desired column size with a class like .col-6 or .col-lg-2. Here's an example:

<div class="container">
  <div class="row">
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
    <div class="col-sm">
      One of three columns
    </div>
  </div>
</div>
This code snippet is taken from their reference guide at https://getbootstrap.com/docs/4.0/layout/grid/

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

Custom Tooltips arrow is not receiving the CSS styling

I have implemented ReactTooltip from the ReactTooltip library You can view an example here Component Setup <ReactTooltip className={styles.customTheme} id={id} place={placement} effect="solid"> {children} </ReactTooltip> Stylin ...

Is there a common issue in web browsers? Neglecting the position relative attribute on 'tbody', 'tr', and 'td' elements?

Trying to absolutely position elements within tbody, tr, and td may not work in certain browsers. While it behaves as expected in Firefox, it does not work properly in IE, Edge, and Chrome. If you apply position: relative to tbody, tr, or td, it will be i ...

CSS confusion: What's causing the header to not align horizontally and the footer to not justify evenly spaced?

I am new to coding and experimenting with CSS flexbox to design a responsive layout. I am struggling with aligning the header elements horizontally in the widest viewport and adjusting the footer to space out evenly. For the header, I attempted using disp ...

Issue with Bootstrap 4 Dropdown Menu not directing to specified href destination

Project URL: You can download the file by clicking on "Download bootstrap menu file for testing" I have implemented a Bootstrap 4 hover menu that works fine on desktop, but on mobile devices, it converts to a clickable menu. Everything is functional so ...

Customizing alert message styles in Java script: Changing color and font of specific parts

I have been attempting to change a specific part of text to be bold and displayed in red color. Unfortunately, this does not seem to work on Microsoft Edge. Here is my code: alert("Hi how are you my friend"); The section that needs to be formatted: "fri ...

Issue observed with the functionality of checkAll and uncheckAll after a user interacts with a single checkbox

After completing an Angular course on Udemy, I decided to implement a custom checkbox in my Angular app. However, I encountered an issue where the UI was not updating properly when using checkAll and uncheckAll functions after the user interacted with an i ...

Tips for applying a jQuery class when the page is both scrolled and clicked

As I work on building a HTML website, I encountered an interesting challenge. I want to create a dynamic feature where, as users scroll through the page, certain sections are highlighted in the navigation menu based on their view. While I have managed to a ...

Enlarge the div with a click

I was looking for a solution on how to make a div expand when clicked using jQuery I came across a tutorial that seemed simple and perfect, but I couldn't get it to work when I tried to replicate the code. Do you know if this code is still valid wit ...

One cannot focus on HTML if it's disabled

I am currently exploring options to prevent an input from receiving focus without disabling it entirely. I need the backend to still retrieve data, but I want to restrict user editing of the input fields at certain times. Disabling the input is not an opti ...

What is the best way to access bootstrap col and row styles without needing to import the entire framework?

I am currently in the process of developing a react app using styled-components and I am looking to design a component that mimics the functionality of the col col-x classes from bootstrap. Additionally, I also want to create another component for the row ...

Having trouble with the dropdown menu in Bootstrap?

I'm having trouble creating a responsive dropdown menu. When I click on the dropdown items, nothing happens. Here's the code: <div class="navbar-header"> <button type="button" class="navbar-toggel" data-toggel="collapse" data-target="#m ...

Moving from one page to another

I am attempting to create a transition effect between sections within a single-page application. All the sections are contained on the same page, with only one section displayed at a time while the rest are set to display none. When a specific event is tri ...

Trouble with CSS Class Showing Up Only When Hovered

My goal is to make the .panel-text element visible only when a user hovers over the panel. I attempted to use the overlay CSS class, but I encountered issues where the text either wouldn't show at all or would always be displayed. Here is what I have ...

Badging with Angular, HTML, and Bootstrap

I've been attempting to integrate Bootstrap 5's badges into my Angular application, but they don't seem to be displaying correctly together. While using Angular 13, the html within the app-root component appears clustered without proper for ...

Neglect the styling of the element wrapper

Imagine I have two divs set up like so: <div name="parent" style="color:blue;padding:5px"> <div name="child" style="background:red"> Text that disregards the color:blue and padding:5px properties, yet still follows the background:red set ...

What could be causing my CSS code to not function properly within Vue.js?

Having trouble with css in VueJs. I can't seem to figure out what I'm doing wrong. Generally, my scoped style css works fine in vuejs, I can target ids and classes without any issues. The problem arises when trying to change the internal css va ...

Utilize the jQuery ajax post method within each loop to handle asynchronous requests, ensuring that the

I am currently working on a jQuery ajax function that is embedded within an each function as it needs to be executed for each post on the website. $('.post .button').each(function() { $(this).click(function() { $.ajax({ url: 'action ...

Reinitializing AngularJS form controls

Check out this codepen example: http://codepen.io/anon/pen/EjKqbW I'm trying to reset the form elements when the user clicks on "Reset". The div elements f1,f2,f3 should be hidden and the searchText box cleared. However, the reset button is not trig ...

When a Grid Item is enclosed in a link, it does not extend over rows

After avoiding HTML/CSS for a long time, I finally decided to dive in and create a simple CSS grid website with 3 items in the grid. Everything was working well and looking exactly as I wanted it to: https://i.sstatic.net/zVQ9U.jpg However, I had the ide ...

jQuery animation that smoothly fades out from the left and fades in from the right

This survey is designed to assist individuals in determining where they should go with a specific type of ticket. Currently, everything is functioning smoothly, but I would like to add a sleek animation to each ul transition. Whenever a button is clicked ...