change svg color in pseudo element

In this article, we'll show you how to change the color of an SVG path in CSS. This can be done by applying a pseudo-class that targets all SVG paths in your document.
In this code example, we'll use a pseudo-element to change SVG's fill color. We can even use multiple pseudo-elements to switch between different colors. This is useful if you have more than one fill color in your SVG file.

change svg color in pseudo element

By RafvsRafvs on May 07, 2021
p:after {
  width: 48px;
  height: 48px;
  display: inline-block;
  content: '';
  -webkit-mask: url(https://gist.githubusercontent.com/mmathys/fbbfbc171233a30e478ad5b87ec4f5d8/raw/cd9219e336b8f3b85579015bdce9665def091bb8/heart.svg) no-repeat 50% 50%;
  mask: url(https://gist.githubusercontent.com/mmathys/fbbfbc171233a30e478ad5b87ec4f5d8/raw/cd9219e336b8f3b85579015bdce9665def091bb8/heart.svg) no-repeat 50% 50%;
  -webkit-mask-size: cover;
  mask-size: cover;
}

.red:after {
  background-color: red;
}

.green:after {
  background-color: green;
}

.blue:after {
  background-color: blue;
}

Source: stackoverflow.com

Add Comment

-3

To change the color of your SVG, it is necessary to use the CSS property background-color. This can be applied to any element on the page that you want to change the color of.

CSS answers related to "change svg color in pseudo element"

View All CSS queries

CSS queries related to "change svg color in pseudo element"

change svg color in pseudo element css pseudo element behind parent target element pseudo-classes change color to white svg with filter how to change svg image color on hover using css change svg color change svg fill color in css mirror css a pseudo :after or :before pseudo class css the syntax of pseudo-class in css pseudo elements css What is a pseudo selector? css pseudo-class no children `@apply` cannot be used with either cannot be found, or its actual definition includes a pseudo-selector like add pseudo buttons many pseudo selectors in css css pseudo elements css pseudo classes pseudo class css :hover pseudo selector css pseudo class how to insert icons pseudo content set svg background color css svg stroke color tailwind svg color change border highlight color on an input text element when i focus a element change element css css flip svg vertically center an svg css svg width 100% html align svg to text svg tailwind css animate svg circle radius wrap DOM elements in SVG using before and after content url svg css bind 'fill' inside ':svg:path' with scss variables svg css animation rotate css for svg css background half one color the other half another color hcss change highlight color mat slide toggle change color html how to change highlight color how to change the background color in css change placeholder color css url do not change color of visited links input date icon color change change input border color when selected how to change the color of the undeline in css change scrollbar color change the color of an hr how to change hyperlink color in css change color of bullet points css change icon color to gradient css css onclick change color change button color html css change background color of page how to change checkbox checked color in css css change text color how to change background color in css change link color in wordpress how to change only bullet color in css change bullet color css list css focus change color focus on input change label color change text color li css change material icons color css change hover color link in wordpress li color change css how to change color of hyperlink in css how to change highlight color on website javafx change button background color change color select arrow css cf7 on class hover another class color change change highlight color html html change button color change the color of a checkbox css style rule that expands the element to cover any floating content within the element how to apply a transition to a child element when hovering over parent element change element in iframe css hover change another element how to change another element on hover css hover change other element css hover change more than one element when change size image not change contrast css bootstrap badge color bootstrap primary color code background color with opacity css underline color how to blur background color in css background color none custom selection color css css placeholder color hex color transparent user preferred color scheme filter for css white color background color semi transparent webkit autofill background color linkedin color hez css input autofill background color text color as gradient css rgb transparent color css background color ionic textarea placeholder color how to have a background image with a color overlay random color scss css background color transition add background image and color css on hover chang only border color of a button css ion-slider pagination color rgb gold color how to split a background into two color in css hex color alpha placeholder color css text color border on clicking a link it gets red color How to overlay image with color in CSS? customize highlight color website gradient font color css css hr color background color css rgb multiple color background ion-select background color apply color tint to image css color gradient background full height @media prefers-color-scheme how to hange the color of your cursor in css background color transparent background color gradient css red color rgb input color custom rgba white color white rgb color button background color remove color checkbox css when clicked background color css how to remove link blue color from a tag using css ionic input line color css color underline mat radio button color random color generator css,javascript,html background color cs rgba css selected color rgba green color css color css filter color how to give 2 different background color css hover apply lighter color css rgb purple color css transparent background color rgba blue color border buttom color placeholder color in css invert png color css gradient text color css css horizontal gradient background color cool ways to color a background with css css set background color background color using css css discord color guide font color css red css color codes border color css tint image with background color css css textarea background color transparent css color of input how to frame a picture with color css css style select arrow color how to transition text color css text background color css how to add color to a image css text color css background image with color overlay gradient css what is difference between background and background-color input backgound color overlay color on image css changong text color css input background color how to chane text color when hover in css alternate color css double color background css css hover darken color background color in hex css css font color background url with color css div color overlay css double border color css css line-through color backgroud color css set background image with color with opecity css css selector color how to give a background color strip in html and css background color for whole page css input autocomplete css color background with three line color css border-color how to do a css color fade mat slider custom color css background color over image

Browse Other Code Languages

CodeProZone