What is the best way to add spacing in between Bootstrap columns?

I am struggling to make all the cards display in a single row when the device screen size is larger than lg, and have them stacked on top of each other when the screen size is smaller. Despite my efforts, I can only get 2 cards to appear in a single row even though I divided the row into 4:4:4. Furthermore, when the device size is reduced, the cards stack properly but their width exceeds the bounds and does not decrease with the screen size reduction, even after specifying col-12. I tried using border-boxing, but it did not work. As a newcomer to HTML, any assistance would be greatly appreciated.

body {
  background-image: linear-gradient(to right, rgb(38, 123, 252), rgb(87, 171, 226));
}

.box {
  background-color: white;
  border-radius: 10px;
  box-sizing: border-box;
  word-wrap: break-word;
}

.heading {
  text-align: center;
  font-size: 40px;
}

.top {
  color: grey;
  font-size: 15px;
  text-align: center;
  margin-bottom: 5px;
}

ul {
  list-style: none;
  font-size: 15px;
  text-align: left;
  padding-left: 0px;
  /* letter-spacing: .1rem; */
}

ul.cross {
  color: grey;
}

ul.tick {
  margin-bottom: 0px;
}

ul.tick li:before {
  content: '✓';
  font-size: 20px;
  font-weight: 100;
  padding-right: 5px;
}

ul.cross li:before {
  content: 'x';
  font-size: 20px;
  font-weight: 100;
  padding-right: 5px;
  color: grey;
}
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aac8c5c5ded9ded8cbdaea9e849c849a">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
  <title>Price tag</title>
</head>

<body>
<div class="container ">
    <div class="row ">
      <div class="col-lg-4 col-12 box my-5 mx-5 mx-lg-2">
        <p class="top">FREE</p>
        <p class="text-center"><span class="heading">$0</span><span>/month</span>
          <hr/>
        </p>
        <ul class="tick">
          <li>Single User</li>
          <li>5GB Storage</li>
          <li>Unlimited Public Projects</li>
          <li>Community Access</li>
        </ul>
        <ul class="cross">
          <li>Unlimited Private Projects</li>
          <li>Dedicated Phone Support</li>
          <li>Free Subdomain</li>
          <li>Monthly Status Reports</li>
        </ul>

      </div>
      <div class="col-lg-4 col-12 box my-5 mx-5 mx-lg-2 ">
        <p class="top">FREE</p>
        <p class="text-center"><span class="heading">$0</span><span>/month</span>
          <hr/>
        </p>
        <ul class="tick">
          <li>Single User</li>
          <li>5GB Storage</li>
          <li>Unlimited Public Projects</li>
          <li>Community Access</li>
        </ul>
        <ul class="cross">
          <li>Unlimited Private Projects</li>
          <li>Dedicated Phone Support</li>
          <li>Free Subdomain</li>
          <li>Monthly Status Reports</li>
        </ul>
      </div>
      <div class="col-lg-4 col-12 box my-5 mx-5 mx-lg-2 ">
        <p class="top">FREE</p>
        <p class="text-center"><span class="heading">$0</span><span>/month</span>
          <hr/>
        </p>
        <ul class="tick">
          <li>Single User</li>
          <li>5GB Storage</li>
          <li>Unlimited Public Projects</li>
          <li>Community Access</li>
        </ul>
        <ul class="cross">
          <li>Unlimited Private Projects</li>
          <li>Dedicated Phone Support</li>
          <li>Free Subdomain</li>
          <li>Monthly Status Reports</li>
        </ul>

      </div>
    </div>
  </div>

Answer №1

A common error is overloading your grid with unnecessary spacing classes, leading to oversized columns within the row. Utilize the grid for structure and keep spacing elements confined within for design purposes. It's important to separate these concerns to maintain clarity in your layout. Bootstrap already applies the border-box property by default.

Furthermore, a proficient editor will detect invalid HTML structures, such as horizontal rules placed inside paragraphs. To address this, you can utilize Bootstrap's border-bottom class on paragraphs instead of using horizontal rules within them.

Remember, convention and Bootstrap's "mobile first" approach suggest ordering breakpoint classes from smallest to largest in your markup to align with the CSS cascade effectively.

body {
  background-image: linear-gradient(to right, rgb(38, 123, 252), rgb(87, 171, 226));
}

.box {
  background-color: white;
  border-radius: 10px;
  box-sizing: border-box;
  word-wrap: break-word;
}

.heading {
  text-align: center;
  font-size: 40px;
}

.top {
  color: grey;
  font-size: 15px;
  text-align: center;
  margin-bottom: 5px;
}

ul {
  list-style: none;
  font-size: 15px;
  text-align: left;
  padding-left: 0px;
  /* letter-spacing: .1rem; */
}

ul.cross {
  color: grey;
}

ul.tick {
  margin-bottom: 0px;
}

ul.tick li:before {
  content: '✓';
  font-size: 20px;
  font-weight: 100;
  padding-right: 5px;
}

ul.cross li:before {
  content: 'x';
  font-size: 20px;
  font-weight: 100;
  padding-right: 5px;
  color: grey;
}
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
  <title>Price tag</title>
</head>

<body>
  <div class="container">
    <div class="row">
      <div class="col-12 col-lg-4">
        <div class="box my-5 mx-5 mx-lg-2 p-3">
          <p class="top">FREE</p>
          <p class="text-center border-bottom"><span class="heading">$0</span><span>/month</span></p>

          <ul class="tick">
            <li>Single User</li>
            <li>5GB Storage</li>
            <li>Unlimited Public Projects</li>
            <li>Community Access</li>
          </ul>

          <ul class="cross">
            <li>Unlimited Private Projects</li>
            <li>Dedicated Phone Support</li>
            <li>Free Subdomain</li>
            <li>Monthly Status Reports</li>
          </ul>
        </div>
      </div>

      <div class="col-12 col-lg-4">
        <div class="box my-5 mx-5 mx-lg-2 p-3">
          <p class="top">FREE</p>
          <p class="text-center border-bottom"><span class="heading">$0</span><span>/month</span></p>

          <ul class="tick">
            <li>Single User</li>
            <li>5GB Storage</li>
            <li>Unlimited Public Projects</li>
            <li>Community Access</li>
          </ul>

          <ul class="cross">
            <li>Unlimited Private Projects</li>
            <li>Dedicated Phone Support</li>
            <li>Free Subdomain</li>
            <li>Monthly Status Reports</li>
          </ul>
        </div>
      </div>

      <div class="col-12 col-lg-4">
        <div class="box my-5 mx-5 mx-lg-2 p-3">
          <p class="top">FREE</p>
          <p class="text-center border-bottom"><span class="heading">$0</span><span>/month</span></p>

          <ul class="tick">
            <li>Single User</li>
            <li>5GB Storage</li>
            <li>Unlimited Public Projects</li>
            <li>Community Access</li>
          </ul>

          <ul class="cross">
            <li>Unlimited Private Projects</li>
            <li>Dedicated Phone Support</li>
            <li>Free Subdomain</li>
            <li>Monthly Status Reports</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</body>

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

Issue with Bootstrap CSS: Default color change not functioning properly on Mobile devices, although it works correctly on Desktop

This is my first website project, you can check it out at www.craigdoesdata.de to see the issue I'm facing with CSS. I apologize if this question seems obvious or if it has already been addressed (I have spent a considerable amount of time searching f ...

Error: The function getAuth has not been defined - Firebase

I have included the code snippets from index.html and index.js for reference. The analytics functionality seems to be working fine, but I am facing an issue with authentication due to an error during testing. Thank you for your help. index.html <script ...

What is the best method to organize HTML tables in Knockout by utilizing a Breeze navigation property?

Currently, I am utilizing Breeze.js to manage my data model within Knockout.js. This involves a simple view model with an adapter library for handling sorting tables on entity properties. The tables are sorted using tablesorter, along with a knockout bindi ...

What is the best way to prevent my images from resizing in a Bootstrap 4 carousel?

I am working on a website where users can upload images of various sizes. These images are then displayed in a Bootstrap 4 carousel. I want to ensure that the carousel maintains a consistent dimension across different screen sizes without changing the widt ...

How to retrieve an array value within a function in AngularJS

<select class="form-control" id="column" ng-model="selectedcolumn" ng-options="column for column in columns"></select> <input type="text" ng-model="test[selectedcolumn]" ng-change="search()" /> Is there a way to retrieve the value o ...

Having trouble with margins not working after adding the clear property in CSS?

I recently applied clear:left to a div in my code, but when I tried adjusting the top margin, nothing seemed to change. Take a look at the snippet below: <!DOCTYPE html> <html> <head> <title>Float</title> <meta cha ...

What is the best way to align a table (datatable) to the left?

How can I align the table to the left without using float:left in the following code? Applying text-align: left to the parent element of the table doesn't seem to work as expected. http://jsfiddle.net/william/B4qJG/1 HTML: <div class="valueList" ...

Can someone provide instructions on how to make a header with Bootstrap?

As a react native developer, I am currently working on a project that involves exporting PDF files from mobile devices. The challenge lies in my lack of expertise in web development and the requirement for the file to be in HTML format. The design I am aim ...

Center alignment is not being applied to the SVG element

I am currently working with React and when my component renders, it displays an SVG inside a div. Here is a snippet of the code: render() { return( <div class="myClass"> <svg> ... </svg> </div> ); ...

Difficulties when running Python scripts containing HTML on localhost or through the command line

I am encountering an issue with my python file that contains some HTML code. The file is intended to display "Hallo" when executed in the command line, and to show formatted HTML when opened in a browser. However, it only prints out the raw HTML code in ...

Achieving universal functionality for html-to-image conversion across all div elements

Using html-to-image, I am able to capture screenshots of a specific div that users can then download as a .png file. My code implementation is as follows: export default function App() { const contentRef = useRef(null); const handleCapture = () => ...

How to vertically align content using Zurb Foundation's equalizer feature?

I am currently utilizing Zurb Foundation 5 along with the equalizer component. In a scenario where I have three columns of equal width, I am aiming to achieve vertical center alignment for the content (text) in the middle column and vertical bottom alignme ...

Create a Sleek Dropdown Navigation Menu with MaterializeCSS in WordPress

I am having trouble displaying the dropdown menu on my WordPress website. How can I make sure the dropdown menu appears properly? functions.php register_nav_menus( array( 'primary' => __( 'Primary Menu', 'TNCTR-OnePage' ) ...

Tips for choosing an image using jQuery from an external HTML page

I'm attempting to embed an HTML page within a div and then individually select all the img tags within that page to display an overlay div on top of the images. Currently, I can insert the HTML into a div named "asd" and it seems like the jQuery is f ...

Basic parallax application, failing to achieve the desired impact

My goal is to create a scrolling effect where the header text moves down slightly, adding some margin on top to keep it in view. I found the perfect example of what I want to achieve with the header text at this website: After spending hours working on i ...

What are some ways to keep text within the boundaries of a div element?

I have tried multiple solutions for this issue, but none seem to be working for me. When I append a paragraph to a div, the text extends beyond the element. Below is the code I am using. Any assistance would be greatly appreciated. CSS: .chat-h { margi ...

Positioning columns in Bootstrap with a fixed layout

Is there a way to troubleshoot issues with Bootstrap col? I attempted the following solution, but it's not yielding the desired outcome: <div class="row"> <div class="col-md-6">Content goes here...</div> <div class="col ...

Apply the child's style if the parent's sibling contains the specified class

I am struggling to add the class "bold" to a child element (span) of a parent element (button.usa-nav-link). This parent element has a sibling (ul li.active) with the class .active. When the sibling is active, I want the child element's text to be bol ...

What is the best way to remove the background from a button that uses -moz

After adding the select component to my page, I noticed a problem with the select button in Firefox. In Chrome, the arrow down button looks normal, like this, but in Firefox it appears differently, as shown in this image. How can I remove the background ...

elements overlap when styled differently

Hello all, I'm in need of some assistance with arranging the items on my webpage. As a beginner, I require detailed explanations as some things may be obvious to you but not to me :) Specifically, I am looking to enhance my header design. My goal is t ...