Does the active class in the boostrap navbar affect the padding?

It appears to only add padding when hovered over, resulting in a somewhat silly appearance.

I am aiming for full width when active is added, similar to the hover effect.

.nav li {
    border-right: 1px dashed grey;
    padding: 0 10px;
}

.nav > li:hover, .nav > li:active, .nav > li:focus {
    background-color: #E7E7E7;
}

JSFiddle Link

Unfortunately, I cannot comment on the answer on StackOverflow. So, here is my response:

Although the initial answer is correct, I prefer the li elements to have better spacing between them, hence the use of padding.

Answer №1

Unfortunately, the answer is no. The padding will remain consistent for both the <li> and <a> elements, regardless of whether the active class is applied or not. This can be confirmed by checking the computed CSS tab in the inspect element feature of your browser.

Your issue may stem from targeting the incorrect class. To resolve this, you can include the following code in your CSS:

.active {
        background-color: #E7E7E7;
}

Visit this link for a working example.

Editor's note: It's worth noting that the addition of the background-color property is necessary because the .active class within Bootstrap only affects the background color of the <a> elements within the <li> tags, rather than the <li> tag itself. This information can be found in line 4032 of the Bootstrap source code here:

Check out the Bootstrap source code for more details.

Answer №2

Include the following CSS code snippet in your stylesheet:

.nav li.active {
  background-color: #E7E7E7;
}

Applying this will resolve the problem you are encountering. You can also view an improved JSFiddle example

Answer №3

Check out this JS Fiddle

It appears to be a padding issue, specifically with the active li in Bootstrap. To override this, you can either ensure your CSS is loaded after Bootstrap or use the !important property as shown below.

.nav li a {
    padding: 15px 15px !important;
}

Prior solution:

.nav .active{
    padding: 0;
}

This should resolve the problem. It seems that there is additional padding being added by bootstrap.min.css based on this screenshot: https://i.sstatic.net/qzqRz.jpg

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

Tips for postponing the appearance of the background image within a div tag

Check out my fiddle here. I am looking to create an effect where the "background-image:" in the CSS loads fully and displays after a 3-second delay with a quick fade-in effect. Until then, the entire div should be in black color. How can this be achie ...

Is it possible for me to set my HTML body class as ".body" in CSS?

CSS .body { background: linear-gradient(-45deg, rgb(255, 0, 0), rgba(216, 29, 29, 0.856), #fdfdfdd7, #234cd5, #ffffff); background-size: 400% 400%; background-repeat:no-repeat; animation: gradient 35s ease infinite; height: 100vh; } HT ...

Guidelines for displaying JSON data in HTML <ul><li></li></ul> format using jQuery within an ASP.NET environment

I am currently developing an asp.net application that involves fetching data from a database in JSON format and displaying it within html ul-li tags using jQuery. Below is a snippet of my Html Page: <html xmlns="http://www.w3.org/1999/xhtml"> <he ...

Tips for eliminating the default hover and active states from a textfield in Material UI

Currently, I am in the process of creating a login form and have incorporated Material UI textfields. However, I am facing an issue where the textfield's default hover and active states cannot be removed. Below is my password textfield: (https://i.st ...

How can I keep the CSS3 animation playing even after the hover state ends?

When hovering over the small menu logo on my site, there's a subtle wiggle effect that I really like. However, I would prefer if the animation played all the way through before repeating. Here's the code I'm currently using: Here is my code ...

Issue with Dropdown Menu functionality while using multiple dropdown options

I am currently experimenting with dropdown menus from W3Schools and have encountered an issue when trying to implement two dropdown options. The code works fine for a single dropdown, but when I try to add a second one using GetElementsByClassName instead ...

Animation of active chat list items on Whatsapp

Has anyone figured out a simple method to create an animation like the one in Whatsapp? For example, when you are on a chat screen and go back to the chat list, have you noticed how an active element is briefly highlighted in gray (to indicate which chat ...

Trying to connect a webpage to my CSS file

Lately, I've been diving into building a new website. It's still in its early stages and unfortunately, I'm struggling to get the style.css file to cooperate. Despite my best efforts scouring the internet for fixes, I haven't had much l ...

Create a layout consisting of two rows, each containing three blocks. Ensure that the layout is responsive by using only HTML and CSS, without relying

Hello there! I am looking to create a responsive layout without using bootstrap or any other framework..... I want to build it from scratch. https://i.stack.imgur.com/GAOkh.png I am aiming for responsive blocks that collapse into one column when the page ...

steps for centering an image on an ionic page

Is there a way to center an image (logo) both horizontally and vertically on the page? <ion-view hide-nav-bar="true"> <ion-content class="backgound-red "> <section class = "home-container"> <div class="row icon-row"> ...

@media doesn't seem to be functioning properly when the screen width is below

I've been working on making my website fully responsive, but I've run into an issue where it won't recognize anything below 980px in width. Here is the CSS code I'm using: @media screen and (max-width:1029px){ h1{ font-size ...

The feature of Switch css does not appear to function properly when used in conjunction with input type

Why does the switch button not work with the input type radio but works with a checkbox button? How can I maintain the radio input and solve this issue? @charset "utf-8"; /* CSS Document */ /* ---------- GENERAL ---------- */ body { background: #4a4a4 ...

Prevent the overlap of text by controlling the positioning of a div element

Below is a simplified version of the layout I'm working with: <div style="position: relative; width:600px;"> <p>Content with unknown length, but very lengthy</p> <div>Content with unknown height</div&g ...

Tips on deactivating automatic email client-specific content (such as Gmail or Outlook) in your emails

I have inserted the following code => <span style="font-size:12px;"><b>Name:</b></span></font><font size="1"><span style="font-size:12px;">Pratik</span> However, when viewed in a browser (such as Outlook ...

Leverage AngularJS to dynamically load CSS stylesheets using ng-repeat

I have organized my stylesheets into separate modules for each include, and I am trying to dynamically load them. However, I am facing some difficulties as when they are rendered, all I see is the following markup for each sheet that should be loaded: < ...

Footer overlapping occurs on a single page

My webpage is having an issue where the footer is overlapping. It seems to be fine on all other pages except for this one. I would prefer not to make any changes to the footer since it's working correctly on other pages. Is there a way to adjust the C ...

Could CSS transitions stack on top of each other?

My current approach involves using CSS to create sliding menus. With JavaScript, I simply apply a class to trigger the CSS animations. The menu consists of 4 columns with list items in desktop mode, but collapses into only headings in mobile mode. These he ...

Unable to locate external CSS files in Firefox using the absolute file path

On my website, I have included the following line in the <head> section: <link type="text/css" href="C:/myApps/app1/images/css/12.02/main.css" rel="stylesheet" /> Upon viewing the page in Firefox 11.0, it appears that the main.css file is not ...

Issue with orientation change when using webkit-overflow-scrolling: touch;

I am currently facing an issue with a fixed position div that has a specified width. The problem arises when the content is long enough to require overflow in one device orientation (landscape), but not the other (portrait) - scrolling stops working if the ...

challenge with incorporating rating system using jQuery

I am facing a simple issue here, but my knowledge of jQuery is limited and I'm struggling to find a solution. I have been trying to implement a rating function using the code from this link: Everything seems to be working fine, but I noticed that on ...