Giter VIP home page Giter VIP logo

defconcepts / a11y.css Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ffoodd/a11y.css

1.0 4.0 0.0 1.99 MB

This CSS file intends to warn developers about possible risks and mistakes that exist in HTML code. It can also be used to roughly evaluate a site's quality by simply including it as an external stylesheet.

Home Page: http://ffoodd.github.io/a11y.css/

Ruby 0.23% CSS 94.11% HTML 5.66%

a11y.css's Introduction

a11y.css

Pronounced « Alix ». Because it's fun.

Introduction

This CSS file intends to warn developers about possible risks and mistakes that exist in HTML code. It can also be used to roughly evaluate a site's quality by simply including it as an external stylesheet.

This file is not a replacement to a complete tool such as OpQuast Reporting. It only intends to show possible weaknesses. You should obviously do some manual check by hand to know whether the code should or should not be fixed.

Acknowledgements

Many references helped me in the making of this stylesheet:

Although let's keep in mind the idea has nothing new (there is an article from Marco Battilana from 2006, and a proposal by Eric Meyer himself from 2007). I only tried to push things further. I suggest you read my article (in French) to learn more about the project.

About colors

In concrete terms, errors, warnings and advices are outlined by a 4px colored border:

  • red for errors;
  • yellow for warnings;
  • blue for obsolete stuff;
  • green for advices.

Those colors are obviously customisable through the configuration file. When hovering marked elements, a little banner should appear on top of your browser displaying what's going on.

About selectors

Given the very long list of selectors to test, they are splitted across several files. Errors are in their own file, advices in their own, and so on.

Please notice that you can build a single level file (obsolete stuff only, for example), and adjust it to your very own issues. You may want to fix errors, or to learn from few advices.

About messages

Each test has its own message, trying to explain and guide you as much as possible. All messages are gathered in a Sass map, in both English and French. It should be quite easy for you to update the messages for internal use if you don't like them.

Test cases and documentation

A full documentation with all test cases is now available on the dedicated site. This is made using Hologram and sseeeedd.

Counters

From now on, CSS counters are incremented on each error/advice/warning and results are displayed with html::after. Since it is added through CSS, it is basically fake-content which is good since it is no more than visual indication for the user to see what's going on.

Note: this counter takes into account possible issues with elements within <head> tag. Related messages are not displayed, but they do increment the counter correctly, as any other issues.

Bookmarklet

You can easily use the latest version of this stylesheet by adding this bookmarklet to your bookmarks:

javascript:(function(){a11ycss=document.createElement('LINK');a11ycss.href='https://rawgit.com/ffoodd/a11y.css/master/css/a11y-en.css';a11ycss.rel='stylesheet';a11ycss.media='all';document.body.appendChild(a11ycss);})();

New You can also generate your own bookmarklet (choosing language and minimum level) on the dedicated page then directly drag it to your bookmarks. Isn't it handy?

About languages

a11y.css currently exists in both English and French: you'll find both files in the css folder. If you want to contribute and add a new language, it is very easy to do:

  1. Add the name of the language in this list;
  2. Copy _a11y-en.scss, rename it _a11y-<your-language>.scss and change the value passed to the set-locale mixin; ". Update this map with your translations. '. Update this map to translate theme names. (. Run sass --update sass:css --style=compressed to generate the new CSS file.

Done!

Edge cases and known issues

  1. Self-closing tags (a.k.a. void elements) do not allow generated content through pseudo-elements. Thus, errors or whatever will correctly be displayed, but not the message on hover. That being said, it should be available for consultation with any DOM reader (DevTools, Firebug or whatever). Here are affected self-closing tags:
  • <area />
  • <base />
  • <br />
  • <col />
  • <command />
  • <embed />
  • <hr />
  • <img />
  • <input />
  • <keygen />
  • <link />
  • <meta />
  • <param />
  • <source />
  • <track />
  • <wbr />
  • <textarea>, <select>, <svg>, <audio>, <video>, <track> and <iframe> aren't void tags but can't contain pseudo-elements as they are replaced elements. Take a look at What The Heck Is A Replaced Element? by @dudleystorey.

Issue #7 opened by @7studio suggested a decent work-around to display messages for those tags, as long as they are followed by a non-self-closing element. Still better than nothing.

  1. Messages are generated through a fixed pseudo-element. However there could be a containing block issue if the parent is a transformed element (transform):
  1. Along the same lines, tests on elements that are contained within <head> cannot be displayed (since <head> is a hidden element). I need to find a way to do this.

*Issue #66 opened by @7studio (again) helped with this point, thanks to an idea from Mathias Bynens.

  1. To avoid cases when outline could be hidden, the property outline-offset is being used in order to display it inside the element (rather than outside). Thanks to @7studio in #4.

Building leveled file

You are now able to customize the file output by targeting a severity treshold. You just have to personalize the single parameter in set-minimum-level mixin. Levels are cumulative, and reflect theme's names:

  • error: only errors;
  • warning: warnings and errors;
  • obsolete: obsolete stuff, warnings and errors;
  • advice: every messages.

We are assuming that looking for advices means that you care about obsoletes, warnings and errors.

Credits to @HugoGiraudel in #69.

Disabling tests

It is possible to disable some specific tests if you build your own a11y.css file. Use the following mixins:

  • disable-errors($keys...)
  • disable-advices($keys...)
  • disable-warnings($keys...)
  • disable-obsoletes($keys...)

For instance, if you want to disable the errors about messing with tabindex and missing href, you can do:

@include disable-errors("tab-order, no-href");

Credits to @HugoGiraudel in #69.

Building docs

With global SassDoc install:

$ npm install sassdoc -g
$ sassdoc sass/ docs/ --verbose --config .sassdocrc

With local SassDoc install:

$ npm install
$ node_modules/sassdoc/bin/sassdoc sass/ docs/ --verbose --config .sassdocrc

Credits and Acknowledgements

Contributors

They helped a lot:

And they took time to open a few issues:

Thank you all!

PS: CSS best practices do not belong to this CSS file. Some selectors are ugly as hell, but we need them in order to select what we need to select.

This project is distributed under MIT license and CC BY 3.0 FR. Copyright (c) 2013 Gaël Poupard

a11y.css's People

Contributors

a5e avatar aidanthreadgold avatar bartveneman avatar ffoodd avatar gaetanbt avatar kittygiraudel avatar nico3333fr avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.