Remove underline on focus from :before element [duplicate] - css

This question already has answers here:
How do I not underline an element in a link?
(2 answers)
Closed 2 years ago.
I'm not able to remove the underline from the :before element.
As you can see from the image, I set the underline of the link during the focus event, but I'd like to have the only text underlined and not the icon.
This is the code for the icon:
a:before {
content: "\f058";
font-family: FontAwesome;
}
This is the code for the focus effect:
a:focus{
text-decoration:underline;
}
I tried something like this but it didn't work.
a:before:focus {
text-decoration:none;
}

Use a span inside the link and apply text-decoration: underline on the inner element
a {
text-decoration: none;
}
a span {
text-decoration: underline;
padding-left: .5em;
}
a::before {
content: "\f058";
font-family: FontAwesome;
}
<span>Lorem ipsum</span>
if you cannot change the markup then you have to fake this behaviour, e.g. using a border with a pseudoelement
a {
text-decoration: none;
position: relative;
}
a::before {
content: "\f058";
font-family: FontAwesome;
width: 2ch;
display: inline-block;
}
a::after {
content: "";
position: absolute;
border: 1px solid currentColor;
left: 2ch;
bottom: 0;
right: 0;
}
a:focus::after {
border: none;
}
Lorem ipsum

Text-decoration when applied on a link "a", will result in the underlining on the icon too. Instead, you can use : The Unarticulated Annotation (Underline) element in your HTML code.
HTML code:
<u>Lorem Ipsum</u>
and then, style the in CSS:
u{
text-decoration: underline;
}

Related

pseudo element across multiple lines to create a continuous underline animation

I have an animated line under links. It works fine for single line links but I have some links that are separated with line breaks <br>
Is there a way to have the animated underline come out along all the lines of the link?
Thanks
body {
padding: 20px;
font-family: Helvetica;
}
a {
font-weight: bold;
color: black;
position: relative;
text-decoration: none;
}
a::before {
content: "";
position: absolute;
width: 0%;
height: 2px;
bottom: 0;
background-color: #000;
transition: all 0.2s;
}
a:hover::before {
width: 100%;
}
my link
<br><br>
this is<br>a much<br>longer link
Use gradient like below:
body {
padding: 20px;
font-family: Helvetica;
}
a {
font-weight: bold;
color: black;
position: relative;
text-decoration: none;
background:linear-gradient(#000,#000) left bottom no-repeat;
background-size:0% 2px;
transition: all 0.5s;
}
a:hover {
background-size:100% 2px;
}
/* this will give another kind of animation (all lines will animate at the same time)*/
.alt {
-webkit-box-decoration-break:clone;
box-decoration-break:clone;
}
my link
<br><br>
this is<br>a much<br>longer link
<br><br>
<a class="alt" href="">this is<br>a much<br>longer link</a>
Related:
How to animate underline from left to right?
How can I achieve a CSS text loading animation over multiple lines?

React Fontawesome CSS pseudo element not rendering inside div but works in Codepen [duplicate]

This question already has answers here:
Font Awesome 5 shows empty square when using the JS+SVG version
(3 answers)
Closed 3 years ago.
I'm running a React application and I need to render a FontAwesome icon inside of a select form field like in this Codepen
To achieve this, I'm using CSS Pseudo Elements, :after to be specific as defined here
Unfortunately, this works well inside of this CodePen but it doesn't render inside the div on my app. I get a box to show that the FontAwesome icon didn't render and the actual icon appears after the select input. See image below for what it looks like.
CSS
.selectdiv {
position: relative;
}
.selectdiv:after {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f107";
color: rgb(75,173,233);
right: 0rem;
top: 0.3rem;
height: 2rem;
padding: 0rem 0rem 0rem 0rem;
position: absolute;
pointer-events: none;
}
/* IE11 hide native button*/
select::-ms-expand {
display: none;
}
.selectdiv select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
color: rgb(75,173,233);
background-color: #ffffff;
background-image: none;
-ms-word-break: normal;
word-break: normal;
}
index.html
<!-- FontAwesome Pseudo Elements Config -->
<script src="https://use.fontawesome.com/releases/v5.12.0/js/all.js" data-search-pseudo-elements></script>
<script>
window.FontAwesomeConfig = {
searchPseudoElements: true
}
</script>
Found an answer here
I followed the 'old way'.
I add this line to index.html
<link href="https://use.fontawesome.com/releases/v5.12.0/css/all.css" rel="stylesheet">
and my CSS now looks like this
.selectdiv {
position: relative;
}
.selectdiv::after {
font-family: "Font Awesome\ 5 Free";
content: "\f107";
font-weight: 600;
color: rgb(75,173,233);
right: 0rem;
top: 0.3rem;
height: 2rem;
padding: 0.2rem 0rem 0rem 0rem;
position: absolute;
pointer-events: none;
}
/* IE11 hide native button*/
select::-ms-expand {
display: none;
}
.selectdiv select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
color: rgb(75,173,233);
background-color: #ffffff;
background-image: none;
-ms-word-break: normal;
word-break: normal;
}

How to remove underline in css for anchors pseudo element in IE

How to remove text-decoration: underline for CSS pseudo element in Internet Explorer?
The + icon has no underline in other browsers (like Google Chrome), but in Internet Explorer the + icon is underlined. How to remove the underline for Internet Explorer?
The Code (https://jsfiddle.net/u5m067xq/4/):
h3 a {
text-decoration:underline;
}
h3 a:before {
display:inline-block;
content: '+';
margin:0;
padding: 4px;
text-decoration:none;
}
<h3>link</h3>
This code is working as you expected. Default styling of the a tag is text-decoration: underline. You will have to set it none.
span {
text-decoration: underline;
}
h3 a:before {
display: inline-block;
content: '+';
margin: 0;
padding: 4px;
text-decoration: none;
}
a {
text-decoration: none;
}
<h3><span>link</span></h3>

Combine :after with :hover for text-decoration of a font icon

How can one get the underline to only apply to the a element and not to the content of the :after?
With the CSS below one can control the color of an :after element on :hover. However, the text-decoration cannot be changed.
Here's the jsfiddle to illustrate the problem:
http://jsfiddle.net/JfGVE/500/
Here's the CSS:
a {
color: green;
text-decoration: none;
}
a:hover {
color: green;
text-decoration: underline;
}
a:after {
font-family: FontAwesome;
content: "\f061";
}
a:hover:after {
color: orange;
text-decoration: none !important;
}
Setting the pseudo-element to display: inline-block will remove the text decoration:
a:after {
font-family: FontAwesome;
content: "\f061";
display: inline-block;
}
The underline will still apply to the space in between because you have an , though — you can prevent this by offsetting the pseudo-element with a margin instead of putting hard spaces in the HTML.
afelixj has almost the best answer here, but it has a non-clickable space, even if you remove all of the actual space in the markup. To fix that, just use padding-right on the anchor to create the space to put the icon, then position it at right: 0: http://jsfiddle.net/JfGVE/591/. Inline-block treats the icon as a character, and it will wrap like text.
Add display: inline-block; to a:after
a {
color: green;
text-decoration: none;
}
a:hover {
color: green;
text-decoration: underline;
}
a:after {
display: inline-block;
font-family: FontAwesome;
content: "\f061";
}
a:hover:after {
color: orange;
text-decoration: none;
}

Pseudo Element Hover and text-decoration

Given the following html:
<span data-icon="✪"></span>A Link
Is it possible to change the text-decoration (to none) on hover? The color will change, the text-decoration will not.
CSS:
a { text-decoration: none; }
a:hover{ text-decoration: underline; }
a:hover [data-icon]:before{
/*Doesn't work*/
text-decoration: none;
/*Works*/
color: red;
}
jsfiddle
As I explained in this other answer, you can use display: inline-block to prevent text-decoration set to an ancestor from propagating to your element:
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a > [data-icon]:before {
display: inline-block; /* Avoid text-decoration propagation from `a` */
content: attr(data-icon);
}
a:hover > [data-icon]:before {
color: red;
}
<span data-icon="✪"></span>A Link
Make things easier and separate it out
http://jsfiddle.net/nyFxn/2/
<span data-icon="✪"></span><span class="text">A Link</span>
CSS
a:hover{ text-decoration: none; }
a:hover [data-icon] {
/*Works*/
color: red;
}
a:hover .text {
text-decoration: underline;
}
Using display: inline-block works in all browsers but IE. To get it to work in IE8+, add overflow:hidden to the pseudo element containing the icon.
If the underline still remains in IE, set line-height: 1 on the pseudo element, so in total you get
a [data-icon]:before {
display: inline-block;
overflow: hidden;
line-height: 1;
}

Resources