Unable to change color of SVG icon when active

I seem to be having trouble getting my SVG element to fill with a specific color in the active state. Despite searching online for examples, I couldn't find much relevant information on this topic. Most of the resources available online focus on hover states for SVGs. While I attempted to use similar methods, I am unable to target my SVG successfully.

The active state works as expected for background and typography elements but doesn't apply to my SVG.

If anything is unclear, please don't hesitate to reach out. Thank you!

To provide better context, I have created a fiddle that can be accessed here

However, I will also include the code below for enhanced visibility. I have simplified the code as much as possible to avoid any confusion due to other elements present.

My HTML:

<div id="contact">

  <div class="contact_Me">

    <div id="contact_Phone3_Wrapper_mb">

        <a href="tel:+xxxxxxxxxxx">

          <h3 class="contact_Me_Line_mb">

              <div class="contact_Box_Svg_1_mb">
                  <svg version="1.1" id="phone" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
                   width="15px" height="15px" viewBox="0 0 15 15" enable-background="new 0 0 15 15" xml:space="preserve">
              <path id="call" opacity="0.4" fill="#444444" d="M12.965,0.042H2.994c-0.61,0-1.108,0.499-1.108,1.108v12.741
                  c0,0.609,0.499,1.108,1.108,1.108h9.971c0.61,0,1.11-0.499,1.11-1.108V1.15C14.073,0.541,13.575,0.042,12.965,0.042 M7.979,14.818
                  c-0.359,0-0.65-0.291-0.65-0.65c0-0.357,0.292-0.65,0.65-0.65c0.36,0,0.651,0.293,0.651,0.65
                  C8.631,14.527,8.339,14.818,7.979,14.818 M12.411,13.337H3.563H3.548V1.704h8.863V13.337z"/>
              </svg>
              </div>

              <span class="contact_Small_Caps_mb">call:</span>

              <span id="contact_Phone_mb">+XX XXX XXX XX XX</span>

          </h3>

        </a>

    </div>

  </div>

My CSS:

#contact_mb {
    width: 100%;
    height: 1000px;
    background: white;
    margin-top: 30em;
    padding-top: 2em;
    background: #e7e7e7;
}


#contact_Phone3_Wrapper_mb {
    display: block;
    margin: 0 auto;
    width: 90%;
    height: 60px;
    margin-bottom: .3em;
    background-color: rgba(249,249,249,.3);
    border: 1px solid #e2e2e2;
 }

#contact_Phone3_Wrapper_mb:active {
   background-color: yellow;
}

#contact_Phone3_Wrapper_mb:active h3, #contact_Phone3_Wrapper_mb:active      .contact_Small_Caps_mb {
  color: #262626;
}

#contact_Phone3_Wrapper_mb:active #call {
  fill: #262626;
}

.contact_Me_Line_mb {
    color: rgba(68,68,68,.4);
    text-align: left;
    line-height: 1em;
    padding-left: 0em;
}

.contact_Box_Svg_1_mb {
      float: left;
      width: 15px;
      height: 15px;
      margin-top: 4px;
      margin-left: 14px;
      margin-right: 12px;
    }

.contact_Small_Caps_mb {
    font-variant: small-caps;
    font-family: times;
    font-size: .8em;
    margin-right: 4px;
    color: rgba(68,68,68,.2);
}

#contact_Phone_mb {
    font-family: arial;
    font-size: .7em;
}

Answer №1

While the functionality is there, the color doesn't stand out as much due to the SVG's opacity being set at 0.4.

To enhance this, simply include opacity: 1 in the active state of the #call SVG element.

#contact_Phone3_Wrapper_mb:active #call {
    fill: #262626;
    opacity: 1;
}

Check out this JSFiddle for reference.

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

Unwanted border appearing on jQuery Carousel Plugin

I am currently using the showbiz jQuery carousel on my products page. I have encountered an issue where, upon clicking the "view more" button, an unwanted border appears around the carousel, but only in Chrome. How can I go about removing this border? Her ...

Creating a "save as" button in HTML - a step by step guide

When browsing the internet, if you want to save an HTML page you are viewing, you typically go to the File menu and select Save As. Is it possible to add a small button at the bottom of an HTML page that performs the same action? Instead of navigating thr ...

What is the best way to ensure consistent Box Overlay Height across multiple boxes?

Is there a way to ensure that overlay box height remains the same even if the text lines are not the same length? Below is a snippet of my code. If you have a solution using jQuery or JS, please provide it. Thank you for your time and effort in trying to h ...

Utilizing Jquery to Toggle Visibility of Images and Text with Buttons

I created a website with two buttons implemented using jQuery. When I click on btn1, the first image appears. Then, when I click on btn2, the first image disappears and the second image associated with btn2 appears. The issue arises when I try to switch b ...

Executing a JQuery function when the webpage is loaded

I am attempting to execute some jQuery code when the page loads, but it doesn't seem to be working properly. The goal is to check if a link has already been saved and, if so, display a table with that information. Is this achievable? It should apply t ...

JavaScript and jQuery are causing my new HTML elements to multiply rapidly - it's mind-boggling!

Greetings! I could use some help with my code. Whenever I use the contmgr_create_media and contmgr_update_order functions together, like when clicking the add image button, new items are created in an exponential pattern (1, 2, 4, 8, 16). However, if I d ...

Guide to integrating various HTML files into a single HTML file with the help of Vue.js

Although I am familiar with using require_once() in PHP, unfortunately, I am unable to use PHP in my current project. I attempted to use w3-include from W3Schools as an alternative, but encountered issues with loading my scripts. Even utilizing JavaScript ...

Understanding how to automatically adjust margins in Bootstrap based on screen width

When viewing in fullscreen, the margins are set to ensure the container fits entirely within the page. However, without the 200px margin in the .gallery class, the container would be too big to fit on the page without scrolling. The problem arises when th ...

Steps for leveraging pdfMake with live data

Recently delving into Angular, I've been exploring the capabilities of pdfMake. While I successfully incorporated static data, I'm facing challenges when attempting to utilize dynamic data. Any guidance on how to achieve this would be greatly app ...

Tips for creating a mobile-friendly contact section on your website

I have encountered an issue with my Contact Us page. Although it works perfectly on desktop, the mobile view is not responsive. Is there anyone who can assist me in resolving this error? Here is the Contact Us page that needs to function properly on mobil ...

Tips for implementing multiple CSS image filters with jQuery

Can you show me how to use jQuery to apply the CSS code below? #centeredImage { -webkit-filter: grayscale(20%) invert(0) blur(1px); } I attempted this method already, but it didn't have any effect. $('#centeredImage').css('-webki ...

The navigation bar remains fixed while the section heading fails to display properly

================================= My webpage acts like a homepage on the web. The issue arises when clicking on a new link, as my navbar is fixed and covers the section heading. I need the page to display the section heading properly even after clicking o ...

Is there a way to display a complete numeric keyboard on Samsung devices using HTML (specifically input type=number)?

When using an input type=number field on my Samsung S7, the keyboard that appears is a limited numeric input that doesn't allow for negative numbers. How can I prompt the phone to display a more comprehensive keyboard? I would like this functionality ...

Navigating a table list in React using arrow keys without inadvertently scrolling the scrollbar

Currently, I've created a table component that contains a list of items. I've implemented hotkeys using the react-hotkeys package to allow users to navigate through the list using the 'arrow up' and 'arrow down' keys. The issu ...

Guide to attaching a page content button to a fixed header

I am currently developing a webpage with a sticky header, and I want to include an animated button that moves onto the header when scrolled past. You can check out my code snippet here: https://jsfiddle.net/ykL50pjf/ The specific ID for the button is #t ...

Incorporating a discreet progress bar into traditional file uploading processes

Have you noticed the trend of new, advanced file uploaders, many of which are Flash-based like SWFUpload? These uploaders can display a progress bar while files are being uploaded, making it much easier for users with shaky or low-bandwidth connections. H ...

Issue with Jquery Fatnav - active state not functioning properly

Currently, I am implementing a Jquery plugin known as fatNav. The documentation for the plugin can be found here: https://github.com/Glitchbone/jquery-fatNav Although everything is functioning properly, I am encountering difficulty getting my active stat ...

"Enhance Your Website with Creative Image Hover Effects using HTML

I'm looking to add a simple hover effect to the images AboutUsLink.png and AboutUsColourLink.png, but I'm unsure of the process. Here is the HTML code: <section class="link1"> <a href="#SecondLink"><img src="images/LogoAndLin ...

Remember to follow the camel case convention when utilizing element.tagName(String) with jSoup

Looking to change the name of an HTML tag using Jsoup in the following way - element.tagName("p:panelGroup"); But when I run this code, the output changes the case and I end up with p:panelgroup. Is there a method to preserve the camel case in the resul ...

Conceal the div element when located beneath an ordered list with a designated

I need help hiding the display of comment information if it is a child comment. Below is my attempt to hide the div with the id "info" if the "ol" element has a class of "children". If you have another method for hiding the div when the comment is a chil ...