Articles in this section
Category / Section

How to customize the Rating control star colors

1 min read

Description:

To customize the rating control star colors based on their state.

 

Solution:

To set different colors for rating stars, use the cssClass property of rating and modify the background image for the stars. Three different types of images can be used for each state. Refer to the following code

<ej:Rating ID="Rating1" runat="server" Value="3" CssClass="custom"></ej:Rating>

 

<style> 

    /*Prevent default state image*/ 

    .custom.e-rating.e-horizontal .e-shape, 

    .custom.e-rating.e-vertical .e-shape, 

    .custom.e-rating.e-horizontal .e-shape-list, 

    .custom.e-rating.e-vertical .e-shape-list, 

    .custom.e-rating.e-horizontal .e-reset, 

    .custom.e-rating.e-vertical .e-reset { 

        backgroundnone; 

    } 

 

    /*Customize reset state image*/ 

    .custom.e-rating.e-horizontal .e-reset, 

    .custom.e-rating.e-vertical .e-reset { 

        backgroundurl('../Content/rating/images/rating1.png') no-repeat; 

        background-size100%; 

        margin1px; 

    } 

 

    /*Customize selected & active state image*/ 

    .custom.e-rating.e-horizontal .e-shape.selected, 

    .custom.e-rating.e-horizontal .e-shape.active, 

    .custom.e-rating.e-vertical .e-shape.selected, 

    .custom.e-rating.e-vertical .e-shape.active { 

        backgroundurl('../Content/rating/images/rating2.png') no-repeat; 

        background-size100%; 

    } 

 

    /*Customize inactive state image*/ 

    .custom.e-rating.e-horizontal .e-shape.inactive, 

    .custom.e-rating.e-vertical .e-shape.inactive, 

    .custom.e-rating.e-horizontal .e-shape-list, 

    .custom.e-rating.e-vertical .e-shape-list { 

        backgroundurl('../Content/rating/images/rating3.png') no-repeat; 

        background-size100%; 

    } 

 

    .custom.e-rating .e-shape.active { 

        background-position0 0; 

    } 

 

    .custom.e-rating.e-horizontal .e-shape-list, 

    .custom.e-rating.e-vertical .e-shape-list { 

        background-position0 0; 

        floatleft; 

    } 

</style> 

 

 

 

Sample: Rating-786604222  

 

Now, rating stars will be displayed as follows

Rating star

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied