I'm having trouble getting these margin classes to work properly in Bootstrap. Can anyone help me figure out what

I'm new to using Bootstrap and struggling with adding margins between elements. I tried adding mb-12 to the navbar class and mt-12 to the container class, but it doesn't seem to be working as expected. Everything else in my code is functioning correctly.

I've searched through the Bootstrap documentation and various forums, but haven't been able to find a solution yet.

<!DOCTYPE html>
<html>
<head>
    <Title>The Title</Title>

    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
    <nav class="navbar mb-12 py-4 bg-warning">
        <H1>Words Here</H1>
    </nav>
    <div class="container mt-12">
        <div class="row">
            <div class="col bg-light">Text</div>
            <div class="col bg-primary">
                <p>Stuff</p>
                <p>Stuff</p>
                <p>Stuff</p>
                <p>Stuff</p>
            </div>
            <div class="col bg-success">Text</div>
        </div>
    </div>
</body>
</html>

Answer №1

The classes mt-12 and mb-12 may not be functioning properly because they are not supported by Bootstrap. Bootstrap only allows padding and margin classes from 0 to 5.

You can refer to the official documentation here

Alternatively, you can create your own custom classes for mt-12 and mb-12 using CSS:

.mb-12{
  margin-bottom: 20px!important; /* Customize the spacing as needed */
}

.mt-12{
  margin-top: 20px!important; /* Customize the spacing as needed */
}

Answer №2

It appears that the class you are using for margin bottom is incorrect. Instead of mb-12, try using mb-2 as it should work properly. Make sure to refer to Bootstrap tutorials to improve your skills;

<!DOCTYPE html>
<html>
<head>
    <Title>The Title</Title>

    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
    <nav class="navbar mb-2 py-4 bg-warning">
        <H1>Words Here</H1>
    </nav>
    <div class="container mt-12">
        <div class="row">
            <div class="col bg-light">Text</div>
            <div class="col bg-primary">
                <p>Stuff</p>
                <p>Stuff</p>
                <p>Stuff</p>
                <p>Stuff</p>
            </div>
            <div class="col bg-success">Text</div>
        </div>
    </div>
</body>
</html>

There are numerous informative tutorials available. For instance

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 the .css file through the graphical user interface, within the managed bean

I have created a jsf page with colorpickers to allow an administrator to modify the main theme of the site, which consists of 4 colors. I have prefixed my main colors in the css file with numbers like this: .element{ background: /*1*/#333333; } When ...

Animate images using mouse vertical movement

Creating websites is just a hobby for me, not something professional. Recently, I came across a beautifully designed website that had some unique features I hadn't seen before, like placing three images in one div (which I researched and learned how t ...

What are the steps to implementing imgix-js via command line?

$(document).ready(function () { var imgixOptions = { updateOnResizeDown : true, updateOnPinchZoom : true, fitImgTagToContainerWidth: true, fitImgTagToContainerHeight: true, autoInsertCSSBestPractices: true, ...

How to align a Google chart to the left on a webpage with the help of bootstrap 3

On my webpage, I have the following div elements: <div><h2>Test</h2></div> <div id="chart_div" style="width: 1200px; height: 600px;"></div> Without any custom styling, only using the default Bootstrap 3 styles. However ...

Should I use several if get statements on one page, or spread them out across multiple pages in PHP structure?

After working with PHP for a few years, one of my ongoing dilemmas is how to best structure my pages. Should I follow the current approach: if(getValue('action') == "jobsFilter" && getValue('jobType') == "open") ...

Updating the ID's of nested elements in JavaScript when duplicating an element

After a fruitless search on Google, I have turned to the experts on SO for assistance. The challenge: Create a duplicate of a dropdown menu and an input field with the click of a button (which can be done multiple times) The proposed solution: Implement ...

Tips for stopping the loading of background images on an image slider

I am utilizing unslider to showcase an image slider on the landing page of my website. The slides are designed with background images in the CSS, and they adjust based on the media query. My concern is that I don't want all the slider images to load a ...

What order should jquery files be included in?

Today I ran into an issue while trying to add datepicker() to my page. After downloading jqueryui, I added the scripts in the following order: <script type="text/javascript" src="js/jquery.js"></script> <script src="js/superfish.js">< ...

Issue with toggling in react js on mobile devices

Currently, I am working on making my design responsive. My approach involves displaying a basket when the div style is set to "block", and hiding it when the user browses on a mobile device by setting the display to "none". The user can then click on a but ...

CSS specificity in Angular components utilizing the /deep/ selector to target a class outside of the component's scope

I have developed a button component for an Angular Component Library that I am currently working on. The button functions correctly, and its implementation is as follows: <sio-button [buttonLabel]="'Button Text'" [buttonFormat]="&apos ...

Eliminating the margin caused by Twitter Bootstrap's span

Utilizing bootstrap, my aim is to display two spans side by side without any white margin between them. However, when I implement the code, there seems to be a white margin between each span. This is the code in question: <li class="span4" > &l ...

The datepicker in Jquery is hidden beneath a div

I've been using this datepicker in my code for a while now. Recently, I made some changes to the HTML and added AJAX calls. However, when I click on the input field, the datepicker doesn't show up. It seems like it's been added to the DOM co ...

What is the best way to transfer files (html, js, css, and resources) while utilizing socket.io?

I am currently in the process of developing a web application that involves the server updating the HTML content on the browser page at specific time intervals, essentially creating an HTML slideshow. My project directory structure is as follows: project ...

SimpleLightBox refuses to function

Having trouble getting SimpleLightBox to work properly? It seems like when you click on an image, it opens as a regular image on a blank page. I've added the JS and CSS files correctly (I double-checked in the source code) and included the HTML and JS ...

Display full desktop version on mobile devices with minimized view and no need for horizontal scrolling

While it may seem unusual, my client has requested temporarily removing responsiveness from the site to view the desktop version on mobile. I initially tried removing the responsive meta tag, but encountered horizontal scrolls on the page. My goal is to di ...

What is the process for loading current page elements into a Bootstrap modal?

How can I display a form on my page and also open it in a Bootstrap modal when a link is clicked? Is there a way to achieve this without duplicating the markup? I considered wrapping my form with default BS4 modal code: <div class="modal fade" ...

Generating HTML tables with charts using FireFox

I am encountering an issue: My table contains charts and tables that are displayed correctly in browsers. However, when I attempt to print it (as a PDF) in Mozilla Firefox, the third speedometer gets cut off, showing only 2.5 speedometers. Using the "s ...

Challenges experienced during the process of uploading a website to the server

I seem to have encountered an issue where the Navigation background image is missing after uploading my website onto the server. Surprisingly, everything else seems to be working perfectly. What could possibly be the cause of this discrepancy? navbar-de ...

The issue arises when radio buttons allow for multiple selections and labels cannot be displayed in a single row

I am facing an issue with the radio buttons displayed in the Bootstrap format. The labels for the radio buttons are not aligning on the same line as the buttons. Below is the code I am using: <div class="row"> <div class="col-lg-4&q ...

Using React to open a (.json) file through a dialog box and access the contents

I'm struggling to understand how to load a local .json file and access its contents in order to store it in a 'state' variable. Here's the code I have so far: import React, { Component } from 'react' import Files from ' ...