Padding on the left and right in Bootstrap

Here is the code snippet I'm working with:

<div class="col-md-12 pt-5 let-top">
    <h1>A</h1>
</div> 

For small and extra small screens, I am looking to include padding on both the left and right sides. Can anyone help me with the best way to achieve this?

Answer №1

<div class="col-md-12 px-<your number> px-sm-<your number> px-md-0">

This method allows you to set a custom padding for your div under the MD breakpoint, which will be removed once the MD breakpoint is reached.

Keep in mind that "px" signifies that both left and right paddings will be the same. If you want varied padding, make use of the pl and pr classes instead.

It's important to note that the col class in the Bootstrap configuration file already has a predefined gutter, resulting in default paddings on the sides for every col. You have the option to override this by configuring the variables in the file.

Answer №2

It's important to note that bootstrap 4 does not include the xs size, so you won't be able to utilize px-xs-3 (where px indicates padding on both sides).

Here's a helpful tip:

  1. Apply padding to all sizes, including those under sm: <div class="px-3">
  2. Then, remove the padding from sm sizes and up: <div class="px-3 px-sm-0">

Take a look at this code example

Answer №3

Reserve a single column for padding:

<div class="col-md-12 col-xs-10 offset-xs-1  pt-5 let-top">
           <h1>B</h1>
</div>

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

Update the sum upon deleting a feature in an HTML and JavaScript form

Once a row or field is added, this function will display a delete link. When clicked, it will remove the row or field: var ct = 1; function addNewRow(){ ct++; var divElement = document.createElement('div'); divElement.id = ct; // Code to cr ...

Providing an image in a Django web application

I'm having trouble displaying an image on my Django web app. Despite placing the image in the static folder, and the hello.html in the templates folder, I'm still getting a broken image link. Below is the content of hello.html: {% load static %} ...

Adjust the height of each card dynamically based on the tallest card in the row

I am working on a row that looks like this: <div class="row"> <div class="col"> <div class="card"> <div class="card-body"> <h3 class="card-title ...

How can I add rows to the tbody of a table that is already inside a div container?

I have an existing table and I want to append a tbody element to it. Below is an example of the HTML table: <div id="myDiv"> <table class="myTable"> <thead> <tr> <th>ID</th> ...

Generate a custom comment page for every URL identifier

I am currently working on creating a PHP comment page that displays unique comments for each specific URL ID. However, I have encountered an issue where the comment page is shared among all URLs. I understand that I need to add the URL ID (bug ID) to the M ...

Difficulty with the increment of my counter when using addeventlistener

I'm currently facing a challenge that I can't seem to figure out... Here is the issue (in JavaScript): export default { name: "TodoList", data() { return { title: "", content: null, isDone: true, count: 0, n ...

Ways to change specific CSS class properties in a unique style

As a Java programmer using primefaces 5.1, I've encountered some challenges with handling CSS classes. One particular issue I'm facing is the need to override certain CSS properties to remove the rounded corners of a DIV element. The rendered cod ...

Implementing JavaScript to assign a symbol to several <span> elements with identical ids

I have a looping span element on my page that is generated based on the number of records in a database table. The appearance of the span can vary, displaying either one or multiple instances. Each span has the following structure: <span class="add-on" ...

Solving the issue of unnecessary white space when printing from Chrome

Whenever I print from Chrome, there seems to be extra space between lines in the middle of a paragraph! Here is an image showing the difference between print emulation and print preview This excess space is always in the same position on various pages an ...

Leveraging AJAX for managing multiple selection options without the need for a submit button

Currently, I have a page featuring two select buttons. Whenever both are selected, the page should update automatically. Furthermore, each time a new option is chosen, the page needs to keep updating on its own. Below is my HTML code: <form action="" m ...

Tips for maintaining the default page size on your website when adjusting the browser window size

I've been struggling with a problem for quite some time now. How can I maintain the default page size of my website while resizing the browser? Let's assume the page size is 1280x720, how do I ensure that size remains intact when I adjust t ...

When resizing the browser window, this single horizontal page website does not re-center

I am in the process of creating my very first one-page horizontal website using jQuery and the scrollTo plugin. This site consists of 3 screens and initially starts in the center (displaying the middle screen). To achieve this, I decided to set the width o ...

Is there an issue with the second bootstrap navbar overlapping a dropdown-menu from the first navbar?

My issue involves two fixed-top navbars, where the dropdown-menu from the first one is being overlapped by the second navbar. I've tried adjusting z-index, positioning, and overflow properties without success. I have also looked at similar questions b ...

When attempting to execute a function when a hidden div is not displayed, JQuery encounters an

I'm currently attempting to modify the text color of the h2 title with the id ticketSearchTitle when the ticketSearch div is not visible. However, the code I have been using to achieve this seems to cause issues (such as the absence of a pointer icon ...

Is it possible to dynamically alter CSS using PHP?

Here's a little query on my mind. Is it possible to dynamically alter the content of a CSS style using PHP in this manner? <?php header("Content-type: text/css; charset: UTF-8"); $color = "red;"; ?> header { color:<?php print $co ...

What is the best way to separate two <a> tags using only Bootstrap?

Currently, I am utilizing a PHP for loop to display 10 tags on an HTML page. My challenge lies in wanting the <a> tags to be displayed on separate lines with some spacing. It's common practice to handle this through custom CSS, however, is ther ...

Error Encountered in Laravel 5.2 FormBuilder.php

Encountering Laravel 5.2 ErrorException in FormBuilder.php on line 1235 stating that the method 'style' does not exist. This error has me perplexed. I have already made updates to my composer.json file by adding "laravelcollective/html": "^5.2" ...

Tips on placing a white background behind fa-3x (Font-awesome) icons

I am facing challenges while trying to customize the background behind my font-awesome icons. My goal is to create a white background that does not extend beyond the actual icon itself. Currently, the result looks like the image below: https://i.sstatic. ...

What is the best way to eliminate excess padding or margin within an absolute block?

I am working on a project where I want to replicate an illustration similar to this one However, I am encountering an issue with the padding or margin. Here is what I have attempted so far: http://jsfiddle.net/kl94/RZPRS/2/ .circles { background-colo ...

reCAPTCHA failing to prevent users from accessing their accounts

I recently implemented Google reCAPTCHA on my login form to combat spam. Despite following all the necessary steps to set it up, users are still able to log in without checking the checkbox, which is not ideal. My initial thought was that the issue might ...