Bootstrap 5 underline default changed? - html

In Bootstrap 4 i understand it set the default text-decoration to be none.
But using Bootstrap 5 if i just add a raw anchor tag it is now showing both the blue writing and underline.
I was looking to only show the undelrine upon hovering. Is this something bootstrap 5 changed in the release? I cannot find any documentation stating it.
Currently i use:
a {
text-decoration: none;
color: inherit;
}
a:hover {
text-decoration: underline;
color: inherit
}
but this is also affecting any buttons as links e.g.
Answer

Yes, As of Bootstrap 5 alpha1 the migration docs state:
"Links are underlined by default (not just on hover), unless they’re part of specific components"
You could create a special class like this:
.text-underline-hover {
text-decoration: none;
}
.text-underline-hover:hover {
text-decoration: underline;
}
Link
Demo
Or, if you want it to apply to all anchors except for those that contain a class= attribute use:
a:not([class]) {
text-decoration: none;
}
a:not([class]):hover {
text-decoration: underline;
}
This will not effect btn, only links without class will underline on hover.

All-in-one solution
This CSS code for Bootstrap 5 won't underline your <a ...> links (unless hovered over):
even if they have another class like mb-4 etc
unless they have the btn class, in which case they stay untouched.
Code to copy paste into your CSS file:
/* Bootstrap 5 tweak: do not underline links unless hovered over */
a:not([class*="btn"]) {
text-decoration: none;
}
a:not([class*="btn"]):hover {
text-decoration: underline;
}
Proof:
/* Simulate Bootstrap 5 CSS */
a {
text-decoration: underline;
}
a:hover {
text-decoration: underline;
}
a.btn {
text-decoration: none;
border: 1px solid #ccc;
}
a.btn:hover {
text-decoration: none;
border: 1px solid #ccc;
background-color: #ccc;
}
/* Bootstrap 5 tweak: do not underline links unless hovered over */
a:not([class*="btn"]) {
text-decoration: none;
}
a:not([class*="btn"]):hover {
text-decoration: underline;
}
An a link without class<br/>
<br/>
An a link with class cool<br/>
<br/>
An a link with class btn

As the default anchor is now underlined, defining custom CSS rules is tricky as these rules will interfere with components (for example navbars, dropdowns, ...).
The official solution i think will be using .text-decoration-none on all the anchors. It's a bit annoying but it's explicit and, we all hope, future-proof. :)

Your <a> tag also has the btn class that's why you get this behaviour.
class="btn btn-outline-dark mr-2 py-0"
Because buttons in bootstrap also has btn class. That's why with your CSS.
a:hover {
text-decoration: underline;
color: inherit
}
All the buttons with class btn also becomes underlined.
Solution:
Just remove btn btn-outline-dark from <a> and use custom class to style it.
Answer

Related

Why is link underline appearing after clicking the link?

I have an anchor tag styled with
text-decoration: none.
This has removed the underline from my links, which is what I want.
However after the link is clicked, little bits of the link underline appear under the spaces between the icons in the link.
I have something like this
<a ng-click="toggle(this)" style="text-decoration: none">
<i class="fa fa-caret-down" ng-if="!collapsed"></i>
<i class="fa fa-folder-open-o" ng-if="!collapsed"></i>
<i class="fa fa-caret-right" ng-if="collapsed"></i>
<i class="fa fa-folder-o" ng-if="collapsed"></i>
</a>
(Using font awesome icons)
The underline is appearing just under the blank space between the icons.
Is there any way to get rid of that link underline for once and for always?!
That is because the default CSS values for links are declared by different browsers. A link has 4 official states.
Normal
Hover
Active (On mouseclick)
Visited
(Focus)
In CSS you can declare the style for each of these. If you want the link not to display the text-decoration in these states:
a, a:hover, a:active, a:visited, a:focus {
text-decoration:none;
}
Answer to your comment
Yes, you can replace the a with a classname. For instance, you have a link with the class 'myLink'.
You can make the CSS:
.myLink, .myLink:hover, .myLink:active, .myLink:visited, .myLink:focus {
text-decoration:none;
}
The right way and you should cover this by adding the following css in your style sheet definition:
**Longer CSS Styling definition:**
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
**Shorter CSS definition:**
a, a:visited, a:hover, a:active {
text-decoration:none;
}
this will ensure no underlining in all state of links to be absolutely sure that there will not be underlining in any of the links on the page. You can also condense the styling definition in your css so the code isn't long and it's more efficient to control style for all link behaviours because it applies to all of the links on the page when you're defining a
if you want to style it for specific links you'd do the following:
a.nav:link {text-decoration: none; }
a.nav:visited {text-decoration: none; }
a.nav:hover {text-decoration: none; }
a.nav:active {text-decoration: none; }
styled links.
or something completely different adding in colours, overline, font weight, size which are going to be different in each link state for that specific class.
a.external:link {color: #0000ff; font-size: 18pt; font-weight: bold; }
a.external:visited {color: #894f7b; font-weight: bold; }
a.external:hover {text-decoration: overline; background-color: #003399; }
a.external:active {color: red; }
You're using the wrong property... text-decoration-line is not meant for this.
The text-decoration-line property specifies what type of line, if any, the decoration will have
Use text-decoration: none instead
<style>
a{text-decoration:none}
a:visited{text-decoration:none}
</style>
Add a stylesheet to your project

Selectively stopping text-decoration: underline on children of a link tag

Does anybody know if it's possible to prevent underlining on the child of an tag, while underlining the rest of the tag's contents?
Here's an example - you can see this working on JSFiddle. I've tried everything I can think of, but the text underlining continues to be applied to all the text inside the link. I'm viewing on Chrome, but I'm sure this applies to all browsers.
a {
font-size: 32px;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a div {
color: pink;
}
a:hover div,
a:active div,
a:focus div {
text-decoration: none !important;
}​
<a href="http://news.bbc.co.uk">
<div class="inner">I don't want this bit underlined on hover. What's the big deal?</div>
This bit should be underlined on hover. Underlining here is fine. I have no objections to underlinining in this bit.
</a>​
Read this similar answer and its links for more information: Remove :hover on :after elemets
http://jsfiddle.net/thirtydot/ygXy6/4/
CSS:
a {
font-size: 32px;
text-decoration: none;
}
a:hover span {
text-decoration: underline;
}
HTML:
<a href="http://news.bbc.co.uk">
<div class="inner">I don't want this bit underlined on hover. What's the big deal?</div>
<span>This bit should be underlined on hover. Underlining here is fine. I have no objections to underlinining in this bit.</span>
</a>​

Link hover css doesn't work

HTML
<a class="topofpage" href="#top">TOP OF PAGE</a>
CSS
.topofpage{
color: #C00;
text-decoration: none;
}
.topofpage a:hover{
color: #FCO;
text-decoration: none;
}
On mouse over color is not changed to #FCO
Remove the anchor element in your CSS on hover event.
.topofpage:hover{
color: #FC0;
text-decoration: none;
}
Your CSS targets a link that is inside an element with the class topofpage. Put the selectors together to target a link that has the class:
a.topofpage:hover {
color: #FC0;
text-decoration: none;
}
Also, as Pavlo spotted, you are using #FCO instead of #FC0 for the color.
Your problem is simply a confusion between zeros and the letter 'O'.
Your colour is specified as #FCO. It should be #FC0.
The letter 'O' is not a valid digit in CSS colours. This is why your style does not work. It has nothing to do with it being hovered or not; it's a simple typo.
Hope that solves it for you. :-)

'Text-decoration: none' not working in Bootstrap

On hover, my text links have underlines. This is the default in Bootstrap.
I want to keep this, unless the link is within a certain div.
The code I have tried (and several variations) doesn't work.
The HTML:
<div class="wall-entry span5">
<a href="">
<img src="http://www.placehold.it/290x163" />
<div class="wall-address">
<p>Burgundy Street</p>
<p>New Orleans, LA</p>
<p>USA</p>
</div>
</a>
</div>
My CSS:
.wall-entry {
background-color: #black;
position: relative;
img {
opacity:0.4;
filter:alpha(opacity=40); /* For IE8 and earlier */
}
div {
position: absolute;
left: 10px;
bottom: 10px;
p {
line-height: 18px;
margin: 0;
font-family: Neuzit Heavy;
font-size: 18px;
color: white;
text-decoration: none;
}
}
}
div.wall-entry:hover img {
opacity:1;
filter:alpha(opacity=100); /* For IE8 and earlier */
}
a div.wall-entry {text-decoration: none;}
A quick note: I have tested a {text-decoration: none;}, this does work. However, I don't want to change everything. Just the links in this specific case.
put the font-family in quotes for fonts that involve multiple words, first of all:
font-family: "Neuzit Heavy", sans-serif;
then beneath a put .wall-entry a:hover { text-decoration: none; }
You have the order switched around. The item you're targeting should be to the right. For example,
.wrapper .header a in english means "Target all anchor links that are inside of .header, that are inside of .wrapper"
The problem is actually a caused by Twitter Bootstrap's CSS file, not your code.
Twitter Bootstrap's CSS file (bootstrap.min.css was the culprit on my project) gives links underlines multiple times. It gives them an underline when they're hovered over, when they're focused on, and it even makes them blue.
In my project, I specifically assigned my own colors to the text that was inside anchor tags, and the browser rendered their colors correctly, just as I assigned them, however, since the text was wrapped in an anchor tag, the blue underline from the Twitter Bootstrap stylesheet still appeared below all my styled text.
My solution: open bootstrap.min.css (or whatever your Bootstrap stylesheet is called) and search for the term 'underline', and whenever you find 'text-decoration: underline' inside an anchor tag selector, like this:
a:hover, a:focus {
color: #2a6496;
text-decoration: underline;
}
or this:
a, a:visited {
text-decoration: underline;
}
you should go ahead and remove the color and text-decoration rules.
That solved my problem.
This won't work
a div.wall-entry {text-decoration: none;} // Inside 'a' div with class wall-entry
but this will work.
div.wall-entry a{text-decoration: none;} // Inside div with class wall-entry 'a'
because an a tag has text-decoration.
If your link is inside div tags, then you can select your link this way:
div > a:hover {
text-decoration:none;
}
It works fine, even with boostrap used.

How do I remove the default link color of the html hyperlink 'a' tag?

The default link color is blue.
How do I remove the default link color of the html hyperlink tag <a>?
The inherit value:
a { color: inherit; }
… will cause the element to take on the colour of its parent (which is what I think you are looking for).
A live demo follows:
a {
color: inherit;
}
<p>The default color of the html element is black. The default colour of the body and of a paragraph is inherited. This
link would normally take on the default link or visited color, but has been styled to inherit the color from the paragraph.</p>
Try something like this:
a {
color: #0060B6;
text-decoration: none;
}
a:hover {
color:#00A0C6;
text-decoration:none;
cursor:pointer;
}
If text-decoration doesn't work, change it to:
text-decoration: none !important;
The !important rule overrides every other styling to the text-decoration attribute. You can read more about it here.
If you don't want to see the underline and default color which is provided by the browser, you can keep the following code in the top of your main.css file. If you need different color and decoration styling you can easily override the defaults using the below code snippet.
a, a:hover, a:focus, a:active {
text-decoration: none;
color: inherit;
}
.cancela,.cancela:link,.cancela:visited,.cancela:hover,.cancela:focus,.cancela:active{
color: inherit;
text-decoration: none;
}
I felt it necessary to post the above class definition, many of the answers on SO miss some of the states
This is also possible:
a {
all: unset;
}
unset: This keyword indicates to change all the properties applying to
the element or the element's parent to their parent value if they are
inheritable or to their initial value if not. unicode-bidi and
direction values are not affected.
Source: Mozilla description of all
Simply add this in CSS,
a {
color: inherit;
text-decoration: none;
}
that's it, done.
You have to use CSS. Here's an example of changing the default link color, when the link is just sitting there, when it's being hovered and when it's an active link.
a:link {
color: red;
}
a:hover {
color: blue;
}
a:active {
color: green;
}
<a href='http://google.com'>Google</a>
You can use System Color (18.2) values, introduced with CSS 2.0, but deprecated in CSS 3.
a:link, a:hover, a:active { color: WindowText; }
That way your anchor links will have the same color as normal document text on this system.
I had this challenge when I was working on a Rails 6 application using Bootstrap 4.
My challenge was that I didn't want this styling to override the default link styling in the application.
So I created a CSS file called custom.css or custom.scss.
And then defined a new CSS rule with the following properties:
.remove_link_colour {
a, a:hover, a:focus, a:active {
color: inherit;
text-decoration: none;
}
}
Then I called this rule wherever I needed to override the default link styling.
<div class="product-card__buttons">
<button class="btn btn-success remove_link_colour" type="button"><%= link_to 'Edit', edit_product_path(product) %></button>
<button class="btn btn-danger remove_link_colour" type="button"><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></button>
</div>
This solves the issue of overriding the default link styling and removes the default colour, hover, focus, and active styling in the buttons only in places where I call the CSS rule.
That's all.
I hope this helps
a:link{color:inherit;}
this is the simple one line can do all stuffs for you <3
I too wanted to remove the default blue link color of a tag.
As I was using bootstrap version 5 I decided to look for the solution in bootstrap documentation.
I searched for "link color" and the result was this link: "https://getbootstrap.com/docs/5.0/helpers/colored-links/"
bootstrap version 5.0 has a class to customise the link colors which I found very helpful and also I was able to change the default blue color of my 'a' tag without any fuss.
Hope this is helpful.
Here are two methods to remove the default link color:
Method 1: Using inline CSS
Link Text
Method 2: Using a CSS stylesheet
a {
color: black;
}
<style>
a {
color: ;
}
</style>
This code changes the color from the default to what is specified in the style. Using a:hover, you can change the color of the text from the default on hover.
This will work
a:hover, a:focus, a:active {
outline: none;
}
What this does is removes the outline for all the three pseudo-classes.