While this solution may not directly help the original poster, it could be beneficial for others who stumble upon this thread searching for "How to delete a CSS class."
Although CSS does not allow for the removal of a specific class from the DOM, there are ways to eliminate the styles associated with that class, as noted by Quentin. This can be achieved using properties like revert
or unset
(potentially combined with all:
).
For instance, consider the following example where an anchor is styled as a button on touch-enabled devices but reverts back when accessed via mouse input:
.button-anchor {
/* sample class modifying various properties */
display: inline-flex;
justify-content: center;
align-items: center;
column-gap: 0.5em;
background-color: steelblue;
color: white;
border: none;
border-radius: 4px;
padding: 8px 16px;
cursor: pointer;
text-decoration: none;
text-align: center;
}
@media (pointer: fine) {
.button-anchor {
all: revert;
}
}
<a class="button-anchor" href="">click me</a>
Remember to utilize your browser's "responsive design mode" to switch between touch and mouse functions.