Explore the styling options for SVG using CSS to manipulate different properties of the

After saving my SVG image in Illustrator, the code appears like this:

<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="10.3 126 503.7 272" style="enable-background:new 10.3 126 503.7 272;" xml:space="preserve">
<style type="text/css">
    .st0{fill:#B7B7B7;}
    .st1{fill:#33BFC1;}
    .st2{fill:#B23939;}
</style>
<path fill="#B7B7B7" class="st0" d="M20.4,126h113c4.3,0,8"/>
<path class="st1" d="M504,126H390c-4.3,0-8,2.7-9.4,6"/>
<path class="st2" d="M420.9,384.6l-92.2-252"/>
</svg>

Including the SVG in my HTML as follows:

<a><img class="logo" src="logo.svg"></a>

As there are 3 paths within the SVG, I am attempting to style each using CSS without directly editing the SVG file.

I have experimented with the following CSS:

.st0 {
fill:#fff;
}
.st0 path {
fill:#fff;
}

Unfortunately, none of these approaches seem to work.

Answer №1

To ensure proper functionality, it is important for this code to be placed following the previous .st0 declaration.

.st0 {
fill:#fff
}

Here is the correct method for declaring the second example:

path.st0  {
fill:#fff
}

Both of these declarations must come after the svg code block in order to work effectively.

My theory is that the SVG is located in the body while the CSS is being declared in the head section. This may result in the fill:#fff getting overridden by the CSS inside the SVG element.

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

The clash between the position:fixed and overflow:visible styles in CSS

I'm working on a webpage layout that includes an image positioned on the right side of the page. I want to create horizontal scroll bars when the browser window is resized, so I added the overflow: visible property. Additionally, I want the image to b ...

Stylish Card Design

Below is the CSS code: *{margin:0; padding:0; box-sizing:border-box; } img{ display:block; max-width:100%; height:auto; } html{ scroll-behavior:smooth; } body{ min-height:100vh; font-family:fantasy; font-size:1.12 ...

Issues with the functionality of the contact form

I have recently purchased a new template that comes with a contact form featuring ajax and validation. I have tried to implement my script, but it doesn't seem to be working. I suspect there might be an issue on the server-side with my script. Can any ...

Increased impact of dynamically added elements following page transition

After implementing dynamic functionality from jQuery in my code, I encountered an issue where if I navigate back one page and then return to the original page containing the added elements, they seem to trigger twice upon clicking. To troubleshoot, I incl ...

What is the best way to structure the layout: Subdomains or External CSS for Web and Mobile Web?

I'm currently working on designing an application that needs to be compatible with both web and mobile web browsers. Due to the differences in screen sizes, I understand that I will need to create different layouts and views to ensure optimal user exp ...

What is the best way to select an element based on its relationship to another Element object using a selector?

I am currently developing a small library in which I require the ability to select a relative element to the targeted element using the querySelector method. For instance: HTML <div class="target"></div> <div class="relative"></div& ...

Arranging divs using the float property

I am currently working on a Django project where I have a large list of dictionaries in the view: 'description': [ { 'name': 'Parts', 'good': ['Engine', 'Transmission&a ...

An even flexbox grid featuring content of varying sizes and dividers

I am currently in the process of working on a .psd template and utilizing Bootstrap 4. I have encountered an issue with one section that contains multiple rows and columns with varying content. The main problem is with one column where the text inside the ...

Libraries that provide webkit support for all browsers

Looking for a library that supports CSS webkit across various browsers, including older ones like ie6. Preferably written in JavaScript. Any recommendations? ...

Ensuring the bottom border of an element extends to the edge of the screen when utilizing a 960 grid in HTML/CSS

I am currently working on creating a website layout using the 960 grid system developed by Nathansmith. I am facing an issue in extending the bottom border of an element to reach till the end of the screen while keeping the element inside a container div. ...

Choose with text partially aligned on the right side

Is there a way to align a portion of the option's text to the right? Below, you will see a select element with names on the left and "(vertical)" on the right. I want to move "(vertical)" to the right side. Is it possible to achieve this? https://i. ...

How to eliminate the checkbox attribute when using jQuery's clone function

When I try to add a new row using my script code and HTML, the property of the last checkbox is automatically selected if it is checked. In the new row, a checkbox with a check is added, but I want to remove the checkbox when it's checked in the new r ...

Adding and removing/hiding tab-panels in Angular 4 with PrimeNg: A step-by-step guide

I'm currently working on a tabView project with a list of tab-panels. However, I am struggling to find a way to dynamically hide and unhide one of the tab panels based on specific runtime conditions. Does anyone have any suggestions or insights on how ...

In JavaScript, generate a new column when the text exceeds the height of a div

Is it possible to create a multicolumn layout in HTML that flows from left to right, rather than top to bottom? I am looking to define the height and width of each text column div, so that when the text overflows the box, a new column is automatically ge ...

Tips for aligning Picture boxes using CSS

As a newbie, I recently received training in HTML, CSS, and a bit of JavaScript. Currently, I am involved in a project where I display the latest news from an API. The technical aspects of fetching data from the API using JavaScript are handled by a senior ...

Modifying the calendar from a 7-day week to a 5-day week

I am currently in the process of developing a 7-day calendar (Sunday to Saturday) which is functioning well. However, I am interested in adding an option to switch it to a 5-day calendar (Monday to Friday). I was wondering if there is a way to modify the e ...

Center nested rows vertically within an alert box using Bootstrap

Can anyone provide some insight into why the inner row is not vertically centered within its alert-box? I feel like it might have something to do with the nested row structure. Here is a link to the code: https://jsfiddle.net/d2pg4xta/ <div class=" ...

What is the best way to activate a post function using a hyperlink?

I'm struggling to figure out how to call my post function using a link within my navbar. The issue is that I'm working with links in the navbar code, and not sure how to integrate calling the post function with them. Below is the code for my pos ...

Is there a way to set the content to be hidden by default in Jquery?

Can anyone advise on how to modify the provided code snippet, sourced from (http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_show), so that the element remains hidden by default? <!DOCTYPE html> <html> <head> <scrip ...

Is it possible to override CSS classes in Ionic without using app.scss?

I'm currently working on designing a dark theme for my ionic application by watching this tutorial. It's been effective for most of the classes, however, I've encountered some CSS classes that only respond to overrides in app.scss. If I try ...