Canceling changes to an individual element in CSS [duplicate] - css

This question already has answers here:
Apply CSS Style on all elements except with a SPECIFIC ID
(3 answers)
Closed 6 years ago.
How do I cancel the changes to one individual element in CSS?
Example:
a {
text-decoration: line-through;
color: green;
}
Now I would like at the end, a.test to ignore all rules and be displayed in the default way.
The normal colors and decorations of a link would show up on a page without any CSS influence.
All I found was to change every property that changes the element to initial. Is there a universal command that would exempt a.test from all changes?

You can exclude with the :not() CSS pseudo selector
a:not(.test) {
text-decoration: line-through;
color: green;
}
Demo: https://jsfiddle.net/azizn/d17vdf35/

Related

SCSS making visited link not clickable not working [duplicate]

This question already has answers here:
Why doesn't this a:visited css style work?
(6 answers)
Why are certain CSS properties not applied to a:visited? [duplicate]
(1 answer)
Why did browsers limit :visited selector?
(1 answer)
Closed 12 months ago.
I want it such that an a element that is visited and of the class, myclass is lightgreen and not clickable. I am able to make it lightgreen, but it is still clickable.
My code:
a:visited.upvote {
pointer-events: none;
cursor: default;
color: lightgreen;
}
and when that code is applied to all a elements, regardless of class and visited status (a {...}), the link is disabled as it should be.
The pointer-events property can't be applied to the :visited CSS pseudo-class due to:
Privacy restrictions
Because of privacy reasons, browsers strictly limit which
styles you can apply using this pseudo-class, and how they can be
used:
Allowable CSS properties are color, background-color, border-color, border-bottom-color, border-left-color,
border-right-color, border-top-color, column-rule-color,
outline-color, text-decoration-color, and
text-emphasis-color.
More info here.
A workaround would be adding a click event listener to the tags and then add to it a class that would apply the pointer-events: none; like so:
const unclickable = document.getElementById("unclickable")
unclickable.addEventListener("click", makeitso)
function makeitso() {
unclickable.className = "notSoClickableLink"
}
div{
display: flex;
flex-direction: column;
gap: 1rem;
}
.notSoClickableLink{
pointer-events: none;
color: lightgrey;
}
<div>
The first Link
<a id="unclickable" href="#2">Make this a visited Link</a>
</div>
This solution would not track your link tag's state, to circumvent that you can try referring to this post: How can I detect visited and unvisited links on a page?

Why can't I override text-decoration for visited links? [duplicate]

This question already has answers here:
text-decoration not working for visited state link
(3 answers)
Closed 3 years ago.
Please could someone explain why this doesn't seem to work? It's pretty straight-forward. I want links on the page to default to blue without an underline, and one they're clicked, I want it to change to purple with a line-through. However, my code doesn't work.
a {
text-decoration: none;
color: blue;
}
a:visited {
text-decoration: line-through;
color: purple;
}
Google (click me) <-- Once clicked, it should have a line through it<br>
<!-- Had to add an onclick event as clicking the link doesn't seem to work without it -->
Non-existant Site
https://jsfiddle.net/thefuzzy0ne/hfqdsr4z/
I've tried varying combinations of text-decoration-line and text-decoration-style and still nothing seems to work. I normally don't have much trouble with CSS, but this is driving me nuts.
You're limited to the attributes of the visited pseudo-class selector you can change for privacy reasons, so you can only style the following:
color
background-color
border-color
border-bottom-color
border-left-color
border-right-color
border-top-color
column-rule-color
outline-color

CSS apply style with an Id selector [duplicate]

This question already has answers here:
How can I apply styles to multiple classes at once?
(9 answers)
Closed 4 years ago.
Is theres a way with css only to apply a specific style to an element when using an id selector inside a css ??
html:
<div Id="MyClassId"> blablabla </div>
css:
.MyOwnFancyDiv{
font-size: 12pt;
color: #333333;
/* ... */
}
/**
Select a particular element and need to apply the MyOwnFancyDiv style
**/
#MyClassId{
/* want to apply the MyOwnFancyDiv style to this particular element */
}
Thanks
You asked:
I want to apply the MyOwnFancyDiv style to this particular element [the id element]
This can be done as specified -- only via CSS -- like so:
.MyOwnFancyDiv,
#MyClassId {
font-size: 12pt;
color: #333333;
/* ... */
}
This will apply all style rules to each element specified (so the class MyOwnFancyDiv and the id element MyClassId.
This should solve your question. If not, please can you edit and clarify the criteria and scope of your question. Thanks.

What does !important mean in vue.js? [duplicate]

This question already has answers here:
What does !important mean in CSS?
(5 answers)
Closed 6 years ago.
What does !important mean in VueJS?
I am new to vue.js and I am seeing this piece of code included after values in style sheets.
I can't find it in the docs.
!important is used in CSS to make sure that style overrides any competing styles.
lets say I have a button .btn and it was in a container called .btn-container
if I had css this css
.btn {
color: red !important;
}
.btn-container .btn {
color: blue;
}
the .btn color would still be red even though the nested rule is higher in specificity. Once you add the !important it overrides the specificity.
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#The_!important_exception

Excluding a particular style of element [duplicate]

This question already has answers here:
Is it possible to exclude all css styling for one specific div container?
(2 answers)
Closed 8 years ago.
I have defined a style for input elements in HTML,
e.g.
input { font-family: Cambria; font-size: 13pt; }
So it by default applies to all the input elements I write in the page.
Now I want one specific input element with no style; can I do that?
The element selector has a lower priority than the class selector, so you can just add a class:
.special-input { font-family: sans-serif; font-size: 10pt; }

Resources