Troubleshooting: SVG Icon Fails to Appear in Bright Theme Due to CSS

My HTML is structured like this.

<h2 class="mt-10 scroll-m-20 border-b pb-1 text-3xl font-semibold tracking-tight first:mt-0" id="know-your-life">
  <a aria-hidden="true" tabindex="-1" href="#know-your-life">
    <span class="icon icon-link"></span>
  </a>
  Know your life
</h2>

The issue I'm facing is that the icon is visible in dark mode but not in light mode. Here's the relevant HTML and CSS:

:where(h1, h2, h3, h4, h5, h6) {
  position: relative;
}

:where(h1, h2, h3, h4, h5, h6) span.icon.icon-link {
  display: none;
}

:where(h1, h2, h3, h4, h5, h6):hover span.icon.icon-link {
  display: inline;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill="%23000000" fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2...

In dark mode, the icon appears correctly, but it's not visible in light mode. The problem might be related to color settings or filter properties, but a solution eludes me.

https://i.sstatic.net/9QVF9wwK.gif

Can you help identify why the icon isn't displaying in light mode and suggest a fix?

Answer №1

The problem lies within the filter: invert(1); section.

Start by eliminating the :hover part from

:where(h1, h2, h3, h4, h5, h6) span.icon.icon-link
to ensure your icon remains visible at all times. Then, experiment with hovering over it - you'll notice that the color changes only when hovered over. By using invert(1), you shift the color from black to white even in light mode (try disabling the inversion).

For those using older versions of Chrome, check out this thread: CSS prefers-color-scheme works on Firefox but not on Chrome issue

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

Utilize a single image to encompass the entire background/theme

As a beginner, I am eager to learn how to use html and css. I understand the importance of being able to style an entire webpage in order to prevent issues like page overload or cache problems. Are there any easy-to-understand examples available for begi ...

Expanding the axes using Google Charts

Seeking to Expand Y-Axis I am attempting to stretch the Y-axis so that it counts up to 300 instead of just 100. The issue arises when I adjust the Y-axis to reach 300, as the values remain in the same position as they did when counting to 100. Fo ...

Feeling trapped during the process of setting up a intricate jQuery Image Slider

I've hit a roadblock while trying to make changes to the slider located at THIS URL. In the current setup, each thumbnail corresponds to one main display image. Clicking on a thumbnail displays a single image and then proceeds to slide to the next th ...

What are the steps to changing the navbar's color when scrolling down?

I am having trouble changing the color of my navigation bar from transparent to black after the user scrolls down. Despite trying various methods and watching tutorials, I can't seem to get it to work. HTML <nav role='navigation' class= ...

Resources for Vue.js stylesheets

Vue.js is my latest discovery and I have been experimenting with the single file component architecture. A small issue I encountered was that all of my components' styles were being loaded on the page, even if they weren't currently active. Is t ...

Inline CSS not appearing correctly upon initial page load

Is your page rendering incorrectly on the first load but then correct after a refresh? It seems to be related to the "display:inline-block" style. Despite clearing cache before loading, the issue persists and you're unable to find a solution. First L ...

Choose tag using position in a sequence

I am working on updating the label text "E-mail" to say "User Name" in this HTML markup. The only tool I have access to for this task is jQuery. <div class="foo" style="border:1px solid #444"> <span class="field-with-fancyplaceholde ...

Tips for choosing elements based on a specific attribute (such as fill color) in D3.js using the SelectAll method

I have various sets of circles on a map - 10 red circles, 10 blue circles, and 10 green circles. Is there a way to use d3 selectAll or select to specifically choose only the red circles? Are there any alternative methods for achieving this? The color of ...

Tips for preventing H1 from taking up the entire div

I'm currently working on developing a new theme for my WordPress website. One issue I've encountered is that the h1 element is causing the top menu to appear below it instead of on the same line. Can anyone help me overcome this challenge? Here& ...

Expanding the clickable area of a link using the CSS :before pseudo-element selector

I am currently working on a project involving an image slider and I am facing a challenge with the "previous" and "next" arrows. My goal is to have each arrow occupy half of the slider area, but adjusting padding or margins tends to change their position o ...

Different ways to position two header tags on top of each other instead of next to each other

I am attempting to adjust the placement of my header tags so that the second header sits directly below the first one, rather than side by side. Currently, I am using h1 and h2 tags for my headers. I have experimented with placing both headers inside an h ...

Tips on increasing the button size automatically as the elements inside the button grow in size

I have a button with an image and text inside, styled using CSS properties to achieve a specific look. However, I encountered an issue where the text overflows outside of the button when it's too long. I want to find a way to wrap the text inside the ...

Center the div and make it position fixed

Is there a way to position a div in the center of the screen or its parent div, and have it fixed so that it does not shift when its width changes? I have a div containing a table, as shown below: https://i.sstatic.net/OVh2y.png I'm unsure if the oute ...

utilizing the removeClass method to toggle the visibility of a div by removing the "hidden" class

I am currently developing a dynamic game utilizing HTML, CSS, and jQuery. In the lower right corner of the screen, there is a question mark (which is an image file, not text). My objective is to display a help box when the question mark is clicked and held ...

What is the best way to ensure items are aligned to the top of the navbar as a picture is enlarged?

I have searched through various similar questions, but none of them have provided a solution to my specific issue. I have attempted multiple suggestions, but none have been successful. (I am working with bootstrap4) Here is the html code I am using: < ...

Creating a centered horizontal line in a table cell using CSS

element, imagine placing a line in the middle of a table cell (td) like this: To achieve this effect, you can insert a line within the td as shown in the image below: https://i.sstatic.net/Gn8tE.png This allows you to write text while keeping the line v ...

Creating a div that automatically resizes to fit a specific width, with excess content wrapping to the next row

In our project, we currently have a design with 4 div elements arranged in two rows and two columns. However, the client has requested that we allow for multiple div elements within a container that spans 100% width. The inner divs should adjust to fit si ...

Is it possible to dynamically load a specific div when the page loads, relying on the

I am using JQuery SlideUp and slideDown methods to toggle the visibility of panels. How can I load or display the first record's contact information as a default? Currently, it loads blank because I set the panel's display property to none: < ...

Obtain the following image with every click

I have a div with images inside. I created two arrows (previous, next) within a larger div using the src of one of the images as the background URL for each arrow. My goal is to make the next arrow change the large image to the src of the following image w ...

JavaScript Issue Causing Jquery Carousel Dysfunction

I am having trouble with the slider I created using JS Fiddle. The link to the slider is not working and I need some assistance. Click here for the slider <div class="row"> <div id="myCarousel" class="carousel slide vertical"> &l ...