Container will keep items from spreading out

Experiencing an issue with the card layout in my weather dashboard app. The cards within a container are not spreading out evenly to match the 100% width of the header. I want the container with the 5 cards to be the same width as the header and wrap properly on mobile devices. Any assistance would be greatly appreciated. Below is the HTML and CSS code:

This is the HTML code consisting of 5 cards inside the container div.

<body>
    <header>
      <h1> Weather Dashboard </h1>
      <p id="currentDay"> </p>
      <input type="text" class="searchBox" placeholder="City Search">
      <!-- Hidden Recent Searches Bar with Bootstrap -->
      <ul class="list-group list-group-horizontal-sm" hidden>
        <li class="list-group-item">Cras justo odio</li>
        <li class="list-group-item">Dapibus ac facilisis in</li>
        <li class="list-group-item">Morbi leo risus</li>
      </ul>
      <div class="btnContainer">
          <button class= "goBtn"> Go</button>
      </div>
    </header>
    <!-- Cards for weather forecast with Bootstrap -->
    <div class="container">
      <div class="card" style="width: 18rem;">
        <div class="card-body">
          <h5 class="card-title"></h5>
          <h6 class="card-subtitle mb-2 text-muted"></h6>
          <p class="card-text"></p>
        </div>
      </div>
      <div class="card" style="width: 18rem;">
        <div class="card-body">
          <h5 class="card-title"></h5>
          <h6 class="card-subtitle mb-2 text-muted"></h6>
          <p class="card-text"></p>
        </div>
      </div>
header {
    background: rgb(255,255,255, 0.35);
    border-radius: 1rem;
    margin-bottom: 10px;
    padding: 10px;
    width: 90%;
    margin-top: 20px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-content: center;
}
.container {
    display: flex;
    flex-direction: row;
    width: 100%;
    flex-wrap: wrap;
}

.card {
    background: rgb(255,255,255, 0.75);
    font-family: all-round-gothic, sans-serif;
    font-weight: 400;
    font-style: normal;
    border-radius: 1rem;
    margin: 25px;
}

Appreciate any help!

Answer №1

If you want to evenly space out elements using CSS Bootstrap, you can utilize the grid system which consists of 12 columns. To achieve a balanced layout, you can allocate a 1 column margin on each side and have each card occupy 2 columns:

<div class = "container">
        <div class = "row">
            <div class = "col-2 offset-1 mt-5 text-center">
                <div class="card">
                    <div class="card-body">
                      <h5 class="card-title"></h5>
                      <h6 class="card-subtitle mb-2 text-muted"></h6>
                      <p class="card-text"></p>
                    </div>
                  </div>
            </div>
            <div class = "col-2 mt-5 text-center">
                <div class="card">
                    <div class="card-body">
                      <h5 class="card-title"></h5>
                      <h6 class="card-subtitle mb-2 text-muted"></h6>
                      <p class="card-text"></p>
                    </div>
                  </div>
            </div>
            <div class = "col-2 mt-5 text-center">
                <div class="card">
                    <div class="card-body">
                      <h5 class="card-title"></h5>
                      <h6 class="card-subtitle mb-2 text-muted"></h6>
                      <p class="card-text"></p>
                    </div>
                  </div>
            </div>
            <div class = "col-2 mt-5 text-center">
                <div class="card">
                    <div class="card-body">
                      <h5 class="card-title"></h5>
                      <h6 class="card-subtitle mb-2 text-muted"></h6>
                      <p class="card-text"></p>
                    </div>
                  </div>
            </div>
            <div class = "col-2 mt-5 text-center">
                <div class="card">
                    <div class="card-body">
                      <h5 class="card-title"></h5>
                      <h6 class="card-subtitle mb-2 text-muted"></h6>
                      <p class="card-text"></p>
                    </div>
                  </div>
            </div>
        </div>
    </div>

It's important to remember to comment out any conflicting styles in your .container{} CSS to prevent it from affecting the Bootstrap layout.

The final outcome should resemble the image shown here: https://i.sstatic.net/0enpc.png

The five empty boxes at the bottom represent the individual cards in your design.

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

CSS/JS Label Positioner using Mootools, perhaps?

I have been tasked with incorporating a form into our website. It seems simple at first, but this particular form has some interesting JavaScript code in place to ensure that the label for each input field sits inside it. This is a clever feature, but unfo ...

Is it possible to transfer items from one list within a component to another list inside a different component with Vue draggable?

I am having trouble implementing Vue Draggable to move items between lists within a component setup. The issue I'm facing is that the items can be moved within a list, but not from one list to another. The structure involves a Board component that ho ...

What is the best way to incorporate modal window parameters into this code snippet?

JavaScript function: function loadBlockEditor(block, username) { var blockInfo = $.ajax({ url: "in/GameElement/BlockEditor.php", type: "GET", data: 'block=' + block + '&nick=' + username, dataType: "html" }); b ...

Launching a program through a web browser - a step-by-step guide

I am looking to create a specific sequence of events: A web browser opens, and a user logs in (the exact action is not crucial) The user is then redirected to a new page where another program should automatically open This process is similar to what happ ...

Overflow of text arranged horizontally within a span element situated inside a div container

I am currently working on developing a ticketing system that involves using nested div elements to organize content. Each ticket is represented by a main div containing various other nested divs and media such as images. While the functionality of the sys ...

Mobile Apps Plagued by Frozen Preloader Gif Images

Working with jQueryMobile(1.3.1) and Phonegap(2.7.0) for developing Android and iPhone applications has presented me with a challenge regarding the Preloader Image. I am currently using a Gif image as my preloader. The custom function I am using for the p ...

Show the file name in the email signature instead of displaying the image

I'm facing a unique challenge with images in my HTML email signature. Sometimes the images are replaced by their file names on certain email hosts. Interestingly, I can't replicate this error now as the images are displaying correctly again! He ...

What impact does including lang=less in a Vue component's style have on its behavior?

Exploring ways to scope the CSS of my Vue component, I initially considered using less to encapsulate my styles. However, after discovering the scoped attribute as the recommended method, I realized that my approach needed adjustment. In my original setup ...

div.load() results in a complete page reload

When I save form data, my goal is to load only the specific div without refreshing the entire page. However, despite using the preventDefault() command, the form still seems to be posting the whole page. I have tried adding the following code: $("#btn ...

Why is it that Lotus Notes is unable to render this HTML code properly?

I am having trouble with an email that displays properly on every platform except Lotus Notes. Can anyone provide insight as to why this email is not rendering correctly in Notes? Here is a screenshot: img (please note the images are for demonstration pu ...

When a sidebar is added, Bootstrap 5 cards that are supposed to be displayed in a row end up being shown in a column instead

When I have a row of Bootstrap 5 cards that display correctly, but then add a sidebar that causes them to stack in a column instead of remaining in a row. How can I maintain the row layout even with the addition of a sidebar using specific CSS classes or p ...

What is the reason behind Chrome's fullscreen mode turning the background black?

I created a webpage with full-screen functionality and made sure to use the correct CSS properties to ensure that my gradient background covers the entire screen perfectly. However, I encountered an issue when clicking the full-screen button in Chrome - th ...

React error due to setting div scroll height on component mount

In my code, there is a special div/container that contains multiple <p/> tags. The container has a reference called divRef, which is initially set to null using the useRef function. <div ref={divRef} style={styles.messageListContainer}> ...

Ways to expand the play and pause buttons and adjust the height of an HTML audio player

It's clear that the PLAY/PAUSE icons are smaller than intended, and the entire player is thinner than desired, making it difficult for some viewers to see. How can I enlarge the entire player? I have read that we do not have access to individual contr ...

Unable to dismiss message in Django

I'm a beginner in Django and I recently followed a tutorial to add message alerts to my code. The alerts are displaying correctly, but unfortunately, I am having trouble closing them using the 'x' button. https://i.stack.imgur.com/BQS1S.png ...

Is it possible to use JavaScript to toggle the visibility of the date picker when using the HTML5 input type=date?

Looking to personalize the HTML5 input type="date" element by integrating a separate button that triggers the visibility of the date picker dropdown. Struggling to find any information on this customization. Any assistance would be greatly valued! ...

Can WebGL be configured to render offscreen without its canvas being directly connected to the DOM?

Searching for an answer to what I believed would be a simple question has proven to be quite challenging. My goal is to utilize WebGL for image processing and generation tasks, with the intention of working offscreen. Specifically, I aim for WebGL to rende ...

Encountering a CSS issue during the edit process with PHP and JavaScript

I'm encountering an issue when clicking on the edit button, as my data fetched from the DB should be displayed inside a text field. However, I'm facing a CSS-related error: Uncaught TypeError: Cannot read property 'style' of null Belo ...

What is the best way to generate a table with continuously updating content?

If the user input : $sgl = 2; $dbl = 0; $twn = 1; $trp = 0; $quad = 0; $price_room = 250000; I want the result looks like the picture below : https://i.sstatic.net/iQYqr.jpg I have tried the following code : <?php $sgl = 2; $dbl = 0; ...

Every time I try to call the event in jQuery for the second time, it fails to work

I am currently working on a website that features an image gallery powered by the jquery wookmark plugin with filtering capabilities. Recently, I integrated the colorbox plugin (which was provided as an example by wookmark) to enhance the user experience. ...