What is the best way to implement auto-width columns with flexbox in Bootstrap 4?

My goal was to transition from using bootstrap 3 to bootstrap 4 so that I could achieve uniform-sized divs in a row by utilizing flexbox. I acquired the precompiled files from https://getbootstrap.com/docs/4.6/getting-started/download/.

After downloading the files, I placed them in my static folder and executed manage.py collectstatic on my django project. Subsequently, I included them as links in my file.

The resulting html content has been condensed for clarity:

    <!DOCTYPE html>
<script>window.jQuery || document.write('<script src="http://code.jquery.com/jquery-3.5.1.min.js"><\/script>')</script>
<html>
    <head>
            <meta charset="utf-8">
        ...
    
      <script type="text/javascript" src="/static/highcharts/highcharts.src.js"></script>
      <script type="text/javascript" src="/static/highcharts/modules/bullet.src.js"></script> 
      
      ...

      </div>
    </body>
</html>

When assigning classes like "col-md-3" to the div elements, the gauges are displayed in a single row. However, if I only use the "col" class, each gauge takes up a separate row below the previous one. Although this is just a portion of the code, my ultimate aim is to have five gauges in a row, but I am unsure about how to enable automatic adjustment through flexbox or whether I need to activate flexbox in some way. I had assumed it would be integrated into the precompiled version.

What am I overlooking?

Answer №1

Bootstrap follows a mobile-first approach, so it is important to incorporate different classes for varying display sizes:

<div class="row">
    <div class="col-lg-6 col-md-6">
        <h4>My expenses</h4>
        <div id="hccontainer_medabr" style="height:200px;"></div>
    </div>
    <div class="col-lg-6 col-md-6">
        <h4>Sibling's expenses</h4>
        <div id="hccontainer_medjan" style="height:200px;"></div>
    </div>
</div>

UPDATE:

The functionality may vary depending on the Bootstrap version you are using. Ensure you are up-to-date with the latest version to access all features:

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-12 col-sm-offset-0 col-md-12 col-md-offset-0 main">
            <h2>Dashboard Overview</h2>
            <br>
            <div class="container-fluid">
                <div class="container">
                    <div class="row text-white">
                        <div class="col border bg-primary">Column 1</div>
                        <div class="col border bg-primary">Column 2</div>
                        <div class="col border bg-primary">Column 3</div>
                        <div class="col border bg-primary">Column 4</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

    <link rel="stylesheet" type="text/css"
        href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
    <script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js">
    </script>

Answer №2

To tackle this issue, one can utilize the bootstrap col-md-6 class, which inherently provides flexibility across various devices.

<!DOCTYPE html>
<script>window.jQuery || document.write('<script src="http://code.jquery.com/jquery-3.5.1.min.js"><\/script>')</script>
<html>
    <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
            <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
            <meta name="description" content="">
            <meta name="author" content="">
            <title>My project</title>
            <link rel="stylesheet" href="/static/boot/css/bootstrap.min.css">
            <link rel="stylesheet" href="/static/boot/css/bootstrap.css">
            
    </head>
    <body>
        <nav class="navbar navbar-default navbar-fixed-top">
                                         
                      .
                       .
                        .
                     (remaining content)
                     
   </body>
</html>

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

Tips for adjusting breakpoints in the SCSS of Vuetify version 2?

I am currently using scss files and I want to adjust the breakpoints within the css code in vuetify version 2. Unfortunately, I have not been able to locate any information regarding this in the vuetify upgrade guide. In the previous version 1.5, I utili ...

The speed at which Laravel loads local CSS and JS resources is notably sluggish

Experiencing slow loading times for local resources in my Laravel project has been a major issue. The files are unusually small and the cdn is much faster in comparison. Is there a way to resolve this problem? https://i.stack.imgur.com/y5gWF.jpg ...

How to customize the footer in Vuetify's list, menu, and combobox components

I've been struggling to add a footer to the Vuetify components like lists, menus, and comboboxes. Despite trying numerous CSS solutions, I haven't found one that works. What I'm aiming for is to have a fixed bottom button visible at all tim ...

Exporting JSON data from Django

I am attempting to input a word and display it on the page using ajax. I feel like there is something simple that I am overlooking... When sending the information through JQuery, it looks like this: $.ajax({ url: url, type:"POST", data:{'word': ...

"Encountering an error while trying to access LiveServerTestCase in Django (error code 500

Despite following the Django documentation, I am encountering an issue with this example - I am receiving a 500 Internal server error when trying to access the live server with Selenium. My code: import os try: browser_driver = os.environ['BROWS ...

Create an HTML component that expands to fill any leftover space on the page, without using flex

In my current situation, I have two elements positioned side by side with dynamic widths based on their content. The element on the right needs to fill up as much vertical space as possible without a set width. I am looking for an alternative to flexbox d ...

Reveal the hidden div by sliding it up from the bottom

I have a container with brown branches resembling the image, and I'm looking to hide it. When a button is clicked, I want it to reveal from the bottom to the top, almost like it's being unmasked. I've ruled out a typical bottom-up slide anim ...

Utilizing GSAP for crafting a dynamic horizontal scrolling section

I am currently working on creating a unique section that transforms into a horizontal scroller once the items (in this case, images) are visible, and then reverts to a vertical scroller once all the items have been scrolled through. My inspiration and ada ...

Troubleshooting Bootstrap 4: data-keyboard attribute malfunctioning

I am using a Bootstrap 4 carousel and have set the attribute data-keyboard="true" Unfortunately, the keyboard navigation feature is not working even when I focus on the carousel with the mouse first. I want the carousel to be interactive with t ...

What is causing me to receive a reverse match error when using the get_absolute_url method in Django?

views.py class ProfileView(DetailView): model = User template_name ="profile/profile_view.html" class ProfileEdit(UpdateView): model = User form_class = ProfileForm template_name="profile/profile_new.html" models.py #.... models def ...

Positioning the horizontal menu and footer links to the right side of the page

Struggling to get my menu and footer links aligned all the way to the right of the page. Here's what it currently looks like http://prntscr.com/32snbr, and this is the desired alignment http://prntscr.com/32snrm I've shared the HTML code below, ...

Challenges arise when integrating poetry into the deployment of a Django app on Render platform

Currently, I am following the tutorial for setting up Django on Render found at . Everything was progressing smoothly until I reached the section on "Configuring Django for PostgreSQL". Despite copying everything correctly, I encountered errors when attemp ...

When the li is clicked, replicate it and display it in a separate div

When a list item is clicked, I want to clone it and display it in a separate div. If another list item is clicked, the previously displayed item should be replaced with the newly clicked one. Below is my code along with a link to the codepen where you can ...

Ways to prevent a timeout when the score exceeds 1000

Could someone help me with clearing the interval and resetting the score in my code? It seems to be working fine, but when the score goes over 1000 and I hit reset, it doesn’t reset completely. I've tried placing the clearTimeout functions before e ...

Clipped Words & Silhouettes

I'm having trouble ensuring the text in this particular example displays correctly. I am experiencing challenges with the clipping of text and shadows on certain letters, and I'm struggling to identify the root cause as well as the solution. In ...

Is it possible to customize the Angular Kendo Grid to be non-scrollable and automatically adjust its height to fit the row contents?

I'm trying to create a Kendo Grid in Angular that is Non-Scrollable and adjusts its height to fit the row contents. However, my current implementation is not working as expected, as it still gives me a fixed height. <kendo-grid [data]="propertyVie ...

Why isn't the AngularJS injected view resizing to fit the container?

As a novice delving into a project in the MEAN stack, I'm encountering inconsistent HTML previews. When I view it independently versus running it from the project, the display varies. Here's the intended appearance (in standalone preview): imgu ...

Height of Owl Carousel on mobile devices

On my desktop, I have an image that covers the entire screen using Owl Carousel. However, when viewed on a phone device, the same image only takes up one-third of the screen size. How can I adjust the height so that it appears taller on a phone? I' ...

Differences between using CSS properties and AngularJS filters:CSS properties

When working on an angularjs application, one task may be to convert a string to uppercase. There are 2 options available to achieve this, both yielding the same result. However, it is important to consider the scenarios in which one option may be preferre ...

Using Django to update a model using a FormView along with a ModelForm

I'm struggling to understand how to effectively utilize a ModelForm within a FormView in order to update an existing instance. The form is set to POST on the following URL: r'/object/(?P<pk>)/' Instead of using an UpdateView directly ...