The behavior of CSS class attributes can vary depending on the parent classes they are within

Currently, I am facing challenges when attempting to override a class within Jekyll while utilizing Stylus for the CSS.

The issue arises with an inline SVG saved in an HTML file that is included at the start of the page body. It consists of 6 path elements, each belonging to one of three different classes: fill-color1, fill-color2, and fill-color3.

<symbol id="my-icon" viewBox="0 0 5461 1024">
  <title>my-icon</title>
  <path class="fill-color1" d="M33.706 ..."></path>
  ...
</symbol>

I want to use this SVG in two distinct parts of my website, each with different backgrounds. Hence, it seemed ideal to assign unique colors to the fill elements.

In the HTML, the SVG is called as follows:

<svg class="class1 class2 class3">
<use xlink:href="#my-icon"></use></svg>

Where class1 and class2 are classes also utilized for other images (excluding the fill element), whereas class3 is intended to alter the behavior of the fill element. In one instance, it would be like:

<svg class="class1 class2 class3a">
<use xlink:href="#my-icon"></use></svg>

And in the second case:

<svg class="class1 class2 class3b">
<use xlink:href="#my-icon"></use></svg>

Regrettably, I am struggling to grasp how to handle this in CSS. Every attempt so far applies the same color to both instances instead of allowing individual colors. It seems there might be an issue with altering the behavior of different descendant elements, but I cannot be certain. How should the CSS code be structured to address this issue effectively?

Answer №1

Based on my understanding, it seems like you are looking for the following:

.class3a
    .fill-color1
        color red
.class3b
    .fill-color1
        color blue

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

Exploring the versatility of CSS variables in JavaFX

In need to style four buttons in a consistent way, but each one should have its own unique image. Three styles are required: one for normal state, and the others for hover and focused states. Using CSS for this task would involve a lot of repetition, as ...

Revamp the design of the Google image layout

I am trying to replicate the layout of a Google search results page. My goal is to have a full-width div appear on screen when an image is clicked, with a small triangle at the bottom of the clicked image. I attempted to place the img inside another div, ...

Ways to modify the color of a particular list item

I am looking to change the color of only the items in a list that contain a number to blue. Specifically, I want to target the first list (the ol li) that starts with a number in it. ol li { color: blue; } <ol> <li>League 1<br> ...

What is the best way to make the div inside the table cells expand to fill the available space?

I'm having trouble making the inner divs within table cell divs expand and fit their parent div without overlapping the next cell below it. Check out the sandbox for reference I've outlined the areas in grey where I want the cells to be filled. ...

What can I do to prevent my website's font from getting distorted due to the recommended display settings?

I've noticed that newer laptops typically have a display font-size recommendation of 150%, which is causing issues with viewing my webpage correctly. The items appear larger and stretched out on their screens. Is there a way to ensure that users can ...

What is the best solution for setting up a div containing a table with images inside?

I'm looking to achieve the following: <div id="display"> <div id="slideshow1"> <table cellspacing=0><tr><td style="height:200px;padding:0;vertical-align:middle"> <img ... /> </td></tr> ...

Unexpected behavior with animation duration in Safari

We have a project in the works that involves CSS animation. Our goal is to update the animation duration using JavaScript. Although this change is effective in most browsers, it seems to have trouble with Safari and iOS. Below is the code we are using to ...

Angular is throwing error TS2322 stating that the type 'string' cannot be assigned to the type '"canvas" while working with ng-particles

My goal is to incorporate particles.js into the home screen component of my project. I have successfully installed "npm install ng-particles" and "npm install tsparticles." However, even after serving and restarting the application, I am unable to resolve ...

What is the best way to eliminate the blue-box-fill when buttons are clicked?

Check out this screen recorded gif on my device showcasing the blue-box-fill I'm referring to: https://i.stack.imgur.com/ajr2y.gif I attempted the following solution: * { user-select: none; -webkit-user-select: none; /* Safari */ -khtml-user-s ...

Convert a div into a clickable link using JavaScript without using too many classes or any ids

After using shortcodes generated by functions.php in a WordPress parent theme, I have come across the following HTML code: <div class="pricing-table-one left full-width "> <div class="pricing-table-one-border left"> <div class=" ...

Update the text within a textarea by clicking with the power of jquery

Is there a way to clear the content of my textarea on click? Below is the code snippet: http://jsfiddle.net/QMfyP/ <textarea name="adventage" style="width:400px; border-radius: 3px; border-left: 4px solid #6C3" id="adventage" cols="45" rows="5">Sh ...

Inheritance of currentColor in SVG URLs

Seeking the same solution as mentioned in How can an SVG image inherit colors from the HTML document?, specifically when applied to an svg image used as content on a :before pseudo-element. (The intended outcome is for both checkmarks to adopt the red col ...

Should the refresh button be displayed once the animation finishes?

Can anyone provide guidance on how to write jQuery code that will reveal a hidden button after an animation is finished? The button should also be able to refresh the animation for the user to watch again. Check out this fiddle: http://jsfiddle.net/rabela ...

Align the video element to the top left corner using Bootstrap 4

Just getting started with bootstrap and css. I'm trying to insert a video element into a row class and want it to be positioned at the top left of the row without any margins. Currently, the video is centered vertically with space above it. Ideally, ...

Adjust the size of the mat-expansion indicator to your desired height and width

Trying to modify the width and height of the mat indicator has been a bit challenging. Despite following suggestions from other similar questions, such as adjusting the border width and padding, I am still unable to see the changes reflect in my CSS file ...

What are some ways to utilize the pseudo elements ::before and ::after within the Material-UI framework?

Can someone please explain how to use the pseudo-element method in MUI? I couldn't find clear instructions in the documentation, so I decided to post a question here. The docs mention the following about pseudo elements: The box-sizing property is ...

Combine various CSS rectangles into one cohesive design

Hey there! I have 3 unique rectangles defined in my css stylesheet. #background .icicle#ice1 { left: 24%; top: 0%; width: 2%; height: 8%; } #background .icicle#ice2 { left: 26%; top: 0%; width: 2%; height: 16%; } #backgro ...

Responsive column display on mobile devices can be optimized by configuring columns to appear in a 2x3 or 1x6 layout. This can be achieved even with

Currently utilizing the Avada Fusion Theme, my ability to edit core theme HTML files is limited. Fortunately, I do have access to Custom CSS. The challenge I am facing involves adjusting the display of the columns to appear as 2x3 instead of 1x6 on mobil ...

Something is amiss with the PHP email validation functionality

I have been facing issues with the functionality of my form that uses radio buttons to display textboxes. I implemented a PHP script for email validation and redirection upon completion, but it doesn't seem to be functioning correctly. The error messa ...

Opting for css3 translate over using position: left for positioning elements

Why Using translate() for Element Movement is Superior to Pos: abs Top/left Read the full article Lisa Anderson I struggled with implementing a CSS3 translate animation, so I opted for a jQuery solution that achieves the same effect. Click on the X icon . ...