Skip to main content

As you're using Bootstrap 5 and applying a style for the hover state of an accordion button, specifically changing the background image of an ::after pseudo-element. If you want to change the icon colour on hover, you should modify the fill attribute in the SVG's path element. 

Here's an example:

/* Default state */
.accordion-button::after {
 background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23333'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
}
/* Hover state */
.accordion-button:hover::after {
 background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23fff'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z' fill='%23yourColourHere'/%3e%3c/svg%3e");
}

Replace #yourColourHere with the desired colour code for the hover state. This modification explicitly sets the fill attribute in the path element within the SVG for the hover state. 

 

Breakdown

The CSS code you provided sets the background-image property for a pseudo-element (::after) using an inline SVG data URI. Let's break down the elements in this CSS code:

Element Description
background-image Property This property is used to set the background image of an element.
url() Function The url() function is used to specify the location of the image. In this case, it's a data URI.
SVG Data URI The SVG data URI contains the SVG markup encoded as a URL. It starts with "data:image/svg+xml," to indicate that it's an SVG data URI.
<svg> Element The <svg> element is the root of the SVG document. It defines a scalable vector graphic.
Attributes of <svg> Element xmlns='http://www.w3.org/2000/svg': Specifies the XML namespace for SVG.
viewBox='0 0 16 16': Defines the aspect ratio and coordinate system of the SVG.
fill='%23fff': Sets the fill color of the SVG path to white (#fff)
<path> Element The <path> element is used to define a set of connected lines and curves. It's the main graphical element in the SVG.
Attributes of <path> Element fill-rule='evenodd': Specifies the algorithm used to determine the interior of the path. In this case, it's the even-odd rule.
d='M1.646 4.646a.5.5 0 0 1 ...': Defines the shape of the path using a series of commands
fill='%23yourColourHere' Attribute This attribute sets the fill colour of the path. It is set to %23yourColourHere, where %23 represents the URL-encoded hash (#) symbol. You should replace yourColourHere with the desired colour code.

 

How it was applied

.ds-regionds-region--main .accordion h2.accordion-header .accordion-button:hover::after {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23fff'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
}

 

Improve readability

To improve the readability and organization of the CSS code, you can break it down into multiple lines and use indentation. Additionally, you can provide comments to explain the purpose of each selector. Here's a revised version:

/* Styles for the main region in the ds-region component */
.ds-region.ds-region--main {
 /* Styles for the h2 element within the accordion component */
 .accordion h2 {
   /* Styles for the accordion header */
   .accordion-header {
     /* Styles for the accordion button */
     .accordion-button {
       /* Styles for the ::after pseudo-element on hover */
       &:hover::after {
         /* Set the background image using an inline SVG data URI */
         background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23fff'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
       }
     }
   }
 }
}

In this revision:

  • Each selector is on a new line for better readability
  • Indentation is used to visually represent the hierarchy of the selectors
  • Comments are added to explain the purpose of each selector

 

In summary, this CSS code is setting the background image of an element to an SVG with a specified fill color. The SVG contains a path with a specific shape, and the fill colour is initially set to white (#fff), but it can be customised by replacing yourColourHere in the fill attribute with the desired colour code.

Related articles

Andrew Fletcher25 Jul 2023
FontAwesome icons working in CKEditor 5
Using CK Editor 5, I needed to add instructions to a page that held FontAwesome (FA) icons. &nbsp;Included in these instructions were a couple of FA icons. &nbsp;Initially adding them was going to be resolved using Pseudo-elements. &nbsp;Accordingly they would be applied as follows: .download-icon,...