Change the active/visited class in bootstrap for button styling

I'm having trouble customizing the card header on a bootstrap 4 accordion. I can't seem to override the default style set by the preset class.

My goal is to modify .btn-link so that it doesn't have an underline when active or visited. However, applying styles to .btn-link:active and .btn-link:visited doesn't appear to have any effect, and I'm unsure why.

Could it be necessary to directly edit the bootstrap CSS itself? Since I am working in CodePen, I don't have direct access to make changes there.

If anyone has faced this issue before, I would appreciate hearing from you!

You can view the pen on CodePen here: https://codepen.io/jreecebowman/full/dmpLRp/ (the accordion can be found in the 'products' section).

Alternatively, the code is provided below.

Thanks in advance!

html for the first card in the accordion:

<div class="card">
<div class="card-header" id="headingOne">
  <h5 class="mb-0">
    <button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
      Collapsible Group Item #1
    </button>
  </h5>
</div>

<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion1">
  <div class="card-body">
    Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica...
  </div>
</div>

corresponding css:

#products {
padding-top:100px;
min-height:100%;
position:relative;
background-color:whitesmoke;
#accordion1, #accordion2 {
    box-shadow:0px 0px 5px 0px lightgray;
    #headingOne {
        .btn-link {
            color:navy;
            opacity:0.8;
        }
        .btn-link:hover {
            opacity:1.0;
            text-decoration:none;
        }
        .btn-link:active {
            text-decoration:none;
        }
        .btn-link:visited {
            text-decoration:none !important;
        }
    }
}

Answer №1

Make sure to include :hover, :active, and also add :focus for proper styling.

.btn-link:focus { text-decoration: none; }

Here is a suggested code snippet:

#products {
padding-top:100px;
min-height:100%;
position:relative;
background-color:whitesmoke;
#accordion1, #accordion2 {
    box-shadow:0px 0px 5px 0px lightgray;
    #headingOne {
        .btn-link {
            color:navy;
            opacity:0.8;
        }
        .btn-link:hover {
            opacity:1.0;
            text-decoration:none;
        }
        .btn-link:active {
            text-decoration:none;
        }
        .btn-link:focus {
            text-decoration:none;
        }
        .btn-link:visited {
            text-decoration:none !important;
        }
    }
}

Answer №2

The most efficient and quick answer lies in this simple solution:

.btn-link:hover { text-decoration: none !important; }
Overriding Bootstrap classes may not be advisable, hence it is recommended to establish a new class and implement the identical code.

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

Odd behavior observed when clicking on the link

On the initial click with an anchor tag, I am experiencing different behavior compared to subsequent clicks. When the href value is set to "", no HTTP GET request is made on the first click. I cannot determine why the first click would behave differently t ...

Calendar display - Days grouped on the left side, with the times arranged across the top in week view?

I'm curious whether it's feasible to display a comprehensive calendar view featuring the days on the left side for the week and the times across the top. Can such a layout be achieved? https://i.sstatic.net/SFtmG.png ...

Cross-origin resource sharing (CORS) issue encountered while trying to play an mp

I am facing an issue with my React application where it is unable to play audio from a different source due to a CORS error. Example: Interestingly, when I visit https://www.w3schools.com/tags/tag_audio.asp, input the above URL and click play, it works fi ...

Differences between HtmlGenericControl('a') and HtmlAnchor

I recently investigated why one of my applications was running slower than expected. This particular application generates a grid and fills it with work tasks in the form of table cells. Each task contains a link that displays additional information when c ...

Storing and retrieving files with HTML5 local storage

Is there a way for me to utilize HTML5 local storage in order to store a small executable file and subsequently offer it for download via a button click? ...

Updating the text of an element will occur only when the specified condition has been met

I am trying to dynamically change the text within the <span data-testid="recapItemPrice">ZADARMO</span> element from 'ZADARMO' to 'DOHODOU' only when the text inside the parent element 'INDIVIDUÁLNA CENA PREP ...

Which is quicker, generating a gradient using CSS or directly loading an image?

I am curious about the potential benefits of the new CSS3 styling techniques. However, I am unsure if the effort is worth it! (Question: Can jQuery be used to apply a vignetting effect to a webpage?) Appreciate any insights! ...

Display one item at a time and allow the option to skip

I am trying to display only one task at a time. When the user clicks on "skip", the next task should be shown. This could range from a list of 3 tasks to a list of 30 tasks. So how can I display only one task at a time? $("a#skip").click(function() { ...

Is there a way to conceal the parent div when all of its child divs are hidden?

I have a series of dynamically created divs set up like this: <div class='parent'> <div class='child'></div> <div class='child'></div> <div class='child'></div> < ...

Navigating the absence of Prismic's ability to use the <blockquote> element in their rich text editor

My experience with Prismic as a headless CMS has been mostly positive, but I recently encountered an issue that surprised me - the lack of support for a simple blockquote. It's baffling to me that such a basic HTML element is not natively supported by ...

Adding Information to a Material Design Card

Currently, I am delving into frontend development and honing my CSS skills. In my latest project, I have incorporated a mat card which can be viewed in the linked image https://i.sstatic.net/TEDcg.png. Below is an excerpt of my code: <div class=&quo ...

CSS Float issue on resizing: avoid element displacement due to margin or padding (responsive layout)

Having an issue that I need help with: My header includes a menu, news sliding with flexslider, and a search input: The problem occurs when I resize the browser manually or reload it with a smaller width; the right element jumps down, causing a pushdown ...

Database-driven menu selection

I am currently working on creating a dynamic side navigation menu that pulls its content from a database. The goal is to have the main categories displayed on the left-hand side, and when one is clicked, the others will slide down to make room for any subc ...

A guide to using the up and down keys to switch focus between div elements in a react component with TypeScript and CSS

I am currently working with a scenario where data is being displayed within different div elements, and I wish to enable the selection/focus of a specific div when users use the up/down arrow keys. While trying to achieve this functionality by using refs ...

An issue arises when attempting to vertically center text that overlaps

I am currently in the process of learning HTML and CSS with the help of Bootstrap-5 My goal is to have a two-line text perfectly centered both vertically and horizontally. However, I am facing difficulty in getting it aligned properly as it keeps overlapp ...

angular index.html code displayed

I successfully deployed an Angular app on a server in the past without any issues. The Angular version is 6.1.1, Angular CLI version is 6.2.9, npm version is 6.13.4, and node version is 10.18.0 for both local and server environments. The server is running ...

Change the destination of an iFrame upon user click

Is it possible to redirect an iFrame to a different HTML page when clicked by the user? I have an iFrame that is essentially an HTML page. When I click on the iFrame, I want it to take me to another HTML page. This is my code: h1 { ...

Tips on revealing concealed information when creating a printable format of an HTML document

I need to find a way to transform an HTML table into a PDF using JavaScript or jQuery. The challenge I'm facing is that the table contains hidden rows in the HTML, and I want these hidden rows to also appear in the generated PDF. Currently, when I co ...

Retrieve CSS content from a file hosted on the local server

Is it feasible to use a locally hosted CSS file for styling a website managed by a server-based CMS? I am interested in utilizing SASS for local CSS development while retrieving the HTML content from a centrally hosted CMS server. ...

seize the cursor on chrome for windows

I'm experiencing an issue with two cursors appearing in Windows Chrome version 31.0.1650.57. The two cursors are grab and a default arrow. I have applied the following CSS: CSS div { width:200px; height:200px; background-color:maroon; ...