Why isn't the SASS extending button working on anchor tags in Bootstrap 4?

After noticing that I really like the style of the default buttons from pre-Bootstrap 4, I decided to try my hand at creating my own version using SASS code. Here's what I came up with:

.btn-default {
    @extend .btn;
    border-color: #A5A5A5;
}

.btn.btn-default:hover,
.btn.btn-default:focus,
.btn.btn-default:active,
.btn.btn-default.active {
    color: #808080;
}

Interestingly, this code works perfectly if I apply it to a <button> tag, but for some reason, it doesn't work when used on an <a> tag. I'm puzzled as to why it wouldn't work on both elements.

<a href="#" class="btn btn-default">
    Test Anchor
</a>

<button type="submit" class="btn btn-default">
    Test Button
</button>

https://i.sstatic.net/nJ75T.png

I wonder why applying the same styling to the anchor tag isn't working, especially considering that normally assigning the .btn class to an anchor tag should style it like a button.

Answer №1

It's unnecessary to @extend .btn when you are already using it.

The rest of the btn-* variations come with properties like color, background-color, and border-color. To create a btn-default style in CSS, you can do:

.btn-default{
   color:#333;
   background-color:#bbb;
   border-color:#a5a5a5
 }
.btn.btn-default:hover,
.btn.btn-default:focus,
.btn.btn-default:active,
.btn.btn-default.active {
    color: #808080;
}

If you prefer Bootstrap SASS, you can use the button-variant @mixin...

.btn-default {
    @include button-variant(#bbb, #a5a5a5, #bbb, darken(#bbb, 10%), darken(#bbb, 10%), darken(#bbb, 12.5%))
}

Check out the Demo:

These are the parameters for the button-variant mixin:

button-variant($background, $border, $hover-background, $hover-border, $active-background, $active-border)

Answer №2

<a> element does not function like a button. To change this behavior, you can use the code below:

a.btn{
 -webkit-appearance: button;
 -moz-appearance: button;
 appearance: button;

 text-decoration: none;
 color: initial;
}

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 centering font-awesome icons vertically within a button

My aim is to design a block button paired with an associated icon. Given that Bootstrap 4 no longer supports glyphicon, and I have a preference for using fonts or SVG images over PNG images, I have opted to utilize font-awesome v5. The issue lies in the f ...

Design a gradient backdrop resembling a duo of bars for a visually appealing effect

Looking to create a unique background effect that resembles two progress bars as shown in this image: https://i.sstatic.net/LpENZ.png I know how to create one progress bar using linear gradients, but I'm wondering if there's a way to split the b ...

Rearranging columns in Bootstrap 4 beta across multiple containers

Sorry for any language issues in my English. This shows my regular grid: ------------------------------- | A | B | C | ------------------------------- | D (horizontal menu) | ------------------------------- Is it possible to d ...

Tips for dynamically including classes in NextJS component with class names from CMS?

I am in search of a solution that will offer some styling flexibility within a CMS to dynamically alter the classes of specific components within my NextJS application. The code snippet I'm working with is as follows: pages/index.js: ... import clien ...

The importance of having separate CSS styles for various browsers, particularly when dealing with different versions of Internet Explorer like IE6, IE7, IE8, and IE9

I have always been intrigued by the fact that default CSS does not always work across all browsers, often resulting in breaks specifically for IE browsers (6, 7, 8, 9). As a result, we typically find ourselves creating multiple CSS files tailored for dif ...

Utilizing SetInterval for dynamically changing the CSS background image URL

I'm starting to feel frustrated with this situation... I have a solution where the CSS background is coming from a webservice. Currently, the system refreshes the entire page using HTML: <meta http-equiv="refresh" content="300" /> ... body { ...

Press the slide button to reveal hidden text using HTML and CSS

I'm having an issue with my website where I want a button to slide down and reveal text, but currently it's only showing the button with the text already displayed below it. The button isn't functioning as intended when clicked. My goal is f ...

Why won't divs align vertically in the center?

I'm struggling to create a navigation bar layout where the icons are centered both horizontally and vertically within their cells. http://jsfiddle.net/digorydoo/j2v5m7gr/ I can't seem to pinpoint what's causing the issue with my current la ...

Press and hold feature using CSS or JavaScript

When working with a jQuery draggable element, my objective is to change the cursor to a move cursor when clicking and holding the header. I have attempted using CSS active and focus properties, but so far no changes are taking place. ...

Preserving content following the use of jQuery's fadeIn/fadeOut methods

I have a jQuery function that fades in and out a sprite (sprite without text) from one background to another, and it's working as intended. However, this function is also fading out the text within an element. HTML: <div id="menu"> <ul c ...

position the div correctly above the table

I am currently working on creating a scheduler that has specific requirements: Show the working hours for each resource Show the interviews, allow changing the interview duration by resizing, and move the interviews using drag-and-drop functionality. I ...

What is the best method for restricting the visibility of an animation to specific regions within an SVG?

I am seeking assistance with adding a "shine" animation to my SVG. I want the animation to only appear within specific parts of the SVG, but I'm uncertain about how to achieve this. Below is what I have accomplished so far. The aim is for the white ...

What is the best way to add a custom class alongside cdk-overlay-pane for a material menu in Angular 7?

I have a specific requirement to create a mega menu using Angular Material Menu. I attempted to apply some custom styling to the cdk-overlay-pane using my own class, but it did not work as expected. I tried to add a custom class to the mat-menu element us ...

Angular 2 and Bootstrap 4 combine to create a stunning side-by-side image display on your

I can't figure out how to display the images next to each otherhttps://i.sstatic.net/yMGgH.png <div class="row"> <div class="col"> <div *ngFor="let ir of imagesSource"> <div class="row"& ...

I encountered an issue with my h3 element's margin not being applied properly when I attempted to add

I'm facing an issue with the margin for <h3> tag in my HTML code. I want to create some space between the form and the h3 element. Here is the CSS: *{ margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } body{ background-ima ...

Is it possible to convert a Button into an input text field?

Hey there, I'm currently working on a project where I need to create a button that will transform into an input field and a submit button once clicked. I am utilizing React along with Bootstrap for this task. <div className="cold-md-2 col-sm- ...

create a new div at the bottom of a designated page when printing out the content

I am facing a challenge with printing a table that has a variable number of rows via browsers. I need to ensure that the table is followed by a div which remains at the bottom of each page, adjusting its position according to the table's overflow onto ...

Issue with overflow in TailwindCSS design

I'm working on implementing a unique layout using Tailwind CSS for a dashboard. The height of the initial view should match the screen size and remain within those limits at all times. Initially, the blue section of the dashboard will be empty (but ...

What is the reason border-box does not function properly on inline-block elements?

Demo: http://jsfiddle.net/L5jchnpm/ I've encountered an issue where I believed that using display: inline-block would make elements act as both inline and block elements. Additionally, I thought that setting box-sizing: border-box would adjust the w ...

Navigation Icons Menu

I need to customize my navigation by adding a special area on the right side with just three icons: basket, search, and wishlist. Can anyone suggest the best approach to achieve this? I am currently using the Divi theme for my website. Furthermore, I atte ...