Saturday, June 6, 2015

Validating CSS Properties


I came across an interesting post on StackOverflow related to CSS Validation. Here is a link to the question of interest:

Checking for Valid CSS properties

The answer to this question highlights the extremely simplistic manner in which we can validate styles for a web page.

Another common error that happens in the course of web development is the using  invalid CSS class names while styling an element. It would be great if there was a way to validate before we send the page into production that all our CSS styles are indeed valid.

This can be done using the below algorithm:
  1. Enumerate all the applied CSS classes for a web page. This can be done as a per a SO query here
  2. Identify the CSS file resource to which this style belongs.
  3. If step 2 cannot be completed successfully for any class, then we are dealing with an invalid CSS class.

 Hopefully,  this helps someone(including myself when I come back looking around after some time on how this needs to be done ;))



No comments:

Post a Comment