Steps for adding a background color to a selected item in a bootstrap 4 navbar

Does anyone know how to make the background color of an active Bootstrap 4 navbar item cover the full height? I tried adding a background color, but it only applied partially. Here is the CSS code I used:

.active {
   background:rgba(165, 168, 168, 0.329);
}

Answer №1

The excess space within the nav element is due to its padding settings. To resolve this, consider removing the top and bottom padding by applying Bootstrap's spacing utility classes. You can achieve this by adding "px-3 py-0" classes to the nav element.

<nav class="navbar navbar-expand-lg navbar-dark bg-danger fixed-top px-3 py-0"></nav>

You have the flexibility to set the pixel value (px) between 1 to 5.

If you also require a consistent height for the navigation bar, adjust the height property in CSS:

nav {
   height: 50px;
}

nav li a {
   height: 50px;
   line-height: 35px;
}

To ensure that the text aligns centrally within the navigation bar, increase the height of the a element and modify the line-height accordingly.

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

Cannot render <Image> inside <Section> component

As a beginner in React, I am attempting to create an app following a tutorial. In my component, I utilized the figure tag but it's not showing up when inspecting element in Chrome. Here are the code snippets: The tutorial includes a div tag as a chil ...

I am looking to incorporate a dynamic bootstrap background class onto a div that is within a foreach loop

Currently, I am retrieving data from a table named department within the admin dashboard, and this data is dynamic. My goal is to incorporate Bootstrap 4 classes such as "success," "primary," and others onto my div element. The issue I am encountering is ...

Is it possible to utilize bootstrap sizing by considering the size of the containing div?

Setting the Scene Imagine a scenario where two divs are placed side by side. div1: 500px wide div2: taking up the remaining width The goal is to make the items in div2 responsive using Bootstrap so that classes like mt-sm-3 can be utilized for differen ...

`Text-overflow ellipsis should function consistently across both Firefox and Chrome browsers`

A design has been created to showcase captions for articles and their respective statuses. The article name box has a fixed width, with text-overflow:ellipsis applied to trim excessively long names. Additionally, a light grey dotted line is added at the en ...

Placing an image in context with the background image

Looking for guidance on CSS styling. I have successfully set up a responsive background image on my page and now want to add a circular logo positioned at the bottom center of it. However, I am facing an issue where the logo's position changes when th ...

Mysterious CSS Margin/Padding Issue

I am currently tackling a small project and have come across an issue. In the bgContainer class, there are two text elements with space between them, but I want to remove this spacing and I can't figure out where it's coming from. Chrome indicate ...

Styling rounded buttons with GTK and CSS

In my C++ application, I am attempting to create a rounded button by utilizing an external CSS file. Although I have successfully achieved a round button, there is still a pesky rectangular border that remains and I am struggling to figure out how to remo ...

Guide to aligning a WordPress div to the top of the webpage

Currently, I am in the process of creating a page template that features a transparent header. My main goal is to have the #content div align perfectly with the top of the page right below the header. I have experimented with various CSS properties such a ...

Guide to dynamically adding two CSS files in a single component in Angular 8

Within this component, there is a form that needs to support two languages, each with its own unique CSS style - one for left-to-right (ltr) direction, and the other for right-to-left (rtl) direction. Is there a way to conditionally apply two different CS ...

What is the best way to ensure that my Bootstrap 4 columns occupy the full width of the row?

I started by creating a dynamic full-width border gradient. Now, I'm trying to replicate the layout with two large containers side by side, just like in Adobe XD. However, I'm facing an issue with increasing the width of the containers. Here are ...

What is the best way to remove the right border in a label for the final child element?

The label in one of my divs returns multiple different names, here is the HTML view: <div class="customerDisplayFlex"> <div class="" *ngFor="let cust of customers"> <label class="dataLabel"> <input type="radio" ...

What causes the first navigation tab's content to change when selecting another tab?

There seems to be a peculiar issue with my Bootstrap tabs. Whenever I navigate away from the first tab to another tab and then return to the first tab, the content of the first tab gets replaced with the content of the last tab clicked. I have exhausted al ...

The overflow scroll feature seems to be malfunctioning and not working as intended in the

I'm trying to implement the overflow scroll property in a div to display a scroll bar for the user, but I'm facing issues. I'm unsure what the problem could be. The code I'm working with can be found here : http://fiddle.jshell.net/Gg ...

The fixed div is overshadowed by the relative divs with a higher z-index

Hey there, check out my HTML snippet below: <body> <div class="relative1"> <div class="fixed1"> </div> </div> <div class="relative2"> </div> </body> Here's the corresponding CSS: ...

What is the procedure to modify a CSS class from the code-behind file?

So I have a CSS style in my .css class where the color is set to blue for hundreds of buttons. But now, my customer wants an option for green buttons which will be saved by a database field. So I check the field like this: if (!String.Is ...

Adding Bootstrap to a button is a simple process that can enhance the

I am new to using Bootstrap and have a question. I am currently working with CodeIgniter for my website, and I have added the Bootstrap files to the asset folder along with my CodeIgniter file. I want to incorporate Bootstrap CSS into the following code: ...

Is it possible to move between textboxes using arrow keys in HTML?

Is there a way to navigate through textboxes using arrow keys in HTML without relying on jQuery? Possibly utilizing JavaScript, HTML, CSS, or another method? Thank you for your help! <body> <form> <input type="text"&g ...

Creating a user-friendly responsive design similar to Whatsapp web by utilizing Bootstrap 4 and Ember framework

I am currently in the process of creating a user interface similar to Whatsapp web. My tools include Bootstrap 4 and Ember 3.2. The foundation of my idea is set, with a message box positioned at the bottom of the screen using the fixed-bottom Bootstrap cla ...

Animate failed due to the appending and adding of class

$('#clickMe').click(function() { $('#ticketsDemosss').append($('<li>').text('my li goes here')).addClass('fadeIn'); }); <link href="http://s.mlcdn.co/animate.css" rel="stylesheet"/> <script ...

Is there a way to implement tab functionality in jQuery UI through an onclick event?

My goal is to enhance an existing jQuery UI Tab container by adding tab information and then updating the contents through re-initialization. To see a demonstration of what I am trying to achieve, take a look at this JSFiddle: http://jsfiddle.net/dmchale9 ...