Using automatic margins with tabs in the latest version of Bootstrap, known as Bootstrap

Currently exploring Bootstrap 5 and still getting the hang of it - so please bear with me if this question seems a bit rudimentary!

I've been experimenting with tabs to create tabbed panes of local content. I've followed the code provided in the documentation found here: https://getbootstrap.com/docs/5.0/components/navs-tabs/#javascript-behavior

<ul class="nav nav-tabs" id="myTab" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Contact</button>
  </li>
</ul>
<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
  <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
</div>

Everything functions perfectly. It also responds well to justify-content, making it easy to center or distribute the tabs, which is exactly what I need.

However, I'm struggling to get them to split using auto margins (mr-auto and ml-auto) so that, for instance, the first two tabs align on the left and the last one on the right. When I include them in the ul tag, it seems to be ignored (even though the justify-content works fine).

I'm aiming to achieve something similar to what's shown in the flex documentation: https://getbootstrap.com/docs/4.0/utilities/flex/#auto-margins or on Wikipedia where the article and talk tabs are on the left, and the read, edit, and history tabs are on the right. Any ideas on how I could accomplish this?

Answer №1

Update the last li as follows:

<li class="nav-item ms-auto" role="presentation"gt;
    <button class="nav-link" id="contact-tab" data-bs-toggle="tab" data-bs-target="#contact" type="button" role="tab" aria-controls="contact" aria-selected="false">Contact</button>
  </li>

In Bootstrap 5,

  • t - for classes that apply margin-top or padding-top
  • b - for classes that apply margin-bottom or padding-bottom
  • s - for classes that apply margin-left or padding-left in LTR, margin-right or padding-right in RTL
  • e - for classes that apply margin-right or padding-right in LTR, margin-left or padding-left in RTL
  • x - for classes that apply both left and right margins or paddings
  • y - for classes that apply both top and bottom margins or paddings
  • blank - for classes that apply margins or paddings on all 4 sides of the element

For More Information: here

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

Conceal button with CSS when text is brief or character count is restricted

Employing solely CSS code, I have successfully implemented a feature to display and hide full paragraphs. The code snippet below demonstrates its functionality. However, the issue arises when the "Show More" button is visible even for short paragraphs that ...

What is causing find_by_css to return nothing when using nth-child?

Currently, I am facing an issue when trying to extract the "href" link from the following HTML code: https://i.stack.imgur.com/Gtzf4.png This is the code that I'm using: from selenium import webdriver from splinter import Browser from bs4 import Be ...

What could be causing my custom Google font in CSS to not function properly?

I've been trying to change the font-family from Google Fonts in my Bootstrap 5 project, but it's not working as expected. Here's a snippet of my code: HTML <div class="row"> <div class="col-lg-6 col-md-12" ...

Adjusting boxes (both up and across) as the window is resized with Bootstrap 4

CSS .main{ border-radius: 20px; margin-left: 20px; margin-right: 20px } .left{ max-width: 250px; height: 1%; border-radius: 20px; } .right{ max-width: 250px; height: 1%; border-radius: 20px; } .parent-containe ...

What are the steps to add 8 columns to the second row in my table?

this is an example of HTML code that showcases a table structure with multiple rows and columns. You can view the full code snippet here. The table includes different sections, such as section1, section2, section3, and section4 in the first row (tr). In t ...

Position the title of the Bootstrap selectpicker field to the right

I utilized Creative Tim's Material Dashboard Pro to create a select field. My goal is to align both the select field and its options to the right. Currently, I have only been successful in aligning the options while the title and selected option rema ...

Issue with Tailwind CSS table header alignment not properly aligning to the right

Currently, I am facing an issue with tailwindcss where the headers in my table are not following the text-right / text-left / text-center directives. If you want to see the problem yourself, here's a link to the fiddle: https://jsfiddle.net/3u2jgqoc/ ...

What solutions are available to improve the clarity of content affected by CSS transforms?

Currently, I am in the process of creating a contact form using CSS and JavaScript. While searching for inspiration, I came across a great example on CodePen. However, I noticed that the contact form in the example is appearing blurry. I attempted to resol ...

What possible reason could there be for the empty space on the left side?

<ul style="background: blue; list-style: none; width: 40px; height: 40px; color: white"> <li style="float: left; width: 20px; background: red">a</li> <li style="float: left; width: 20px; background: green; height: 40px">b</li ...

Utilizing Jquery to Add Elements and Adjust Element Height

Encountering an unusual issue where the height of a div is not updating when content is appended to it using JQuery. To demonstrate the problem, I have created a simple JSFiddle: http://jsfiddle.net/hf66v/5/ Here is the initial HTML structure: <div i ...

Reposition the span element to the right of the div tag

I need help adjusting the positioning of the elements in this HTML code. How can I move the span element with the image to the right of the div tag? Here is the code snippet: <div style='width:600px;padding-top: 2px;padding-bottom: 1px'& ...

Tips for addressing Navbar collision with body content or other pages using CSS

I have successfully created a navigation bar using CSS and JS. The image below illustrates the example of my navigation bar: https://i.sstatic.net/2l4gj.png The issue I am facing is that when I select "MY ACCOUNT," it displays some content. However, upon ...

Issue with CSS background inner shadow not covering entire background area

A question has arisen regarding the implementation of an inner shadow effect for a background picture that is set to repeat. The current code used for the shadow effect is as follows: background: #202020 url(images/img01.jpg) repeat; -moz-box-shadow: inse ...

Arranging rows and columns in Bootstrap 3 for small screens

My layout is structured as follows: <div class="container"> <div class="row"> <div class="col-md-8> <div class="row"> <div class="col-md-12"> box 1 & ...

Troubleshooting collapsing problems in Bootstrap 5.2 using Webpack and JavaScript

I am currently developing a project utilizing HTML, SASS, and JS with Webpack 5.74.0. My goal is to implement a collapsible feature using Bootstrap 5, however, I ran into some issues while trying to make it work. To troubleshoot, I attempted to direct ...

When I separate the div into its own line in the HTML/CSS code, the behavior changes significantly

I'm encountering an issue with my HTML/CSS structure: .im-wrapper { width: 100%; height: 100%; position: fixed; overflow: hidden auto; top: 0; left: 0; } .im-backdrop { background-color: var(--darkblack); opacity: 80%; width: 1 ...

Ensuring that jQuery(document).ready(function() contains the appropriate content

Recently, I've been attempting to integrate a javascript gallery into my WordPress site. However, I'm encountering some confusion regarding what needs to be included in the .ready(function) to successfully run the gallery. The original jQuery fun ...

Vertical scrolling causes the bottom of the sidebar to be cut off

If you take a look at the following Tailwind CSS, you'll notice that when you scroll down, the sidebar is not fully visible at the bottom. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> ...

What is the best way to display ng-repeat elements in a horizontal layout

Looking for a way to display thumbnails horizontally using ng-repeat in AngularJS and Bootstrap. Any ideas on how to achieve this with CSS or Bootstrap? <div class="row"> <ul class="col-md-4" id="phones"> <li class="thumbnail" ...

Obtain the following image with every click

I have a div with images inside. I created two arrows (previous, next) within a larger div using the src of one of the images as the background URL for each arrow. My goal is to make the next arrow change the large image to the src of the following image w ...