markup.tips
Page | Description | Published On |
---|---|---|
Silence Your CSS Footprint With Sass Silent… | Efficiently group your common styles together to reduce your CSS footprint in this Thinkful project.. | |
Sticking Components above the Fold | Get stuck riding the bleeding edge with this unstable CSS3 feature | |
Creating an Accessible to-do list powered by… | Enhance a simple to–do list with React.js |
|
Adopting Orphans with | Up your typography game with the use of this single HTML entity | |
Making your Markup Speak | Using speakable.jquery.js you too can make your markup talk | |
Loading Modernizr from a CDN | Get the best of both worlds by loading Modernizr from a CDN near you | |
Creating an Accessible Settings Table | Create an accessible settings table using HTML5, CSS3, and a sprinkle of jQuery |
Settings |
Value |
---|---|
site_title |
My Site |
|
|
Media Source | Filesystem |
|
|
JS–Driver | React.js 0.x |
|
|
clipsJSON |
{{"prop":"value"}} |
|
|
compress_css |
Yes |
|
#HTML #JS
Configurable software of any kind can find itself in need of settings to be quickly created, found, and edited. JavaScript
based management components tend to lack in accessibility; we need a HTML–first
solution.
In this tutorial we will start with a simple <table>
element that will be progressively enhanced to become the hyper–accessible example found above.
Our .settings-table
will have 5 settings each with a different input type.
<tr>
elements
<tr>
is always present and displays the setting name/value pair
<tr>
spans all columns and contains an accessible form
.js
users
.setting-form
of each setting is initially hidden using a .js-hide
class
jQuery
is used to show the corresponding .setting-form
of each setting on focus
.no-js
users
.setting-form
contains a standard <form>
that supports .no-js users.Admittedly with an odd approach, this component relies on two rows per setting. Note the use of the classic colspan
attribute. This lets our form be greedy and take up the full width of the component. If you add columns to your table update your colspan
attributes accordingly.
Source HTML
for this example.
Notice the use of the .js-hide
class to hide our forms for asynchronous users. We're using a craft :nth-of-type(4n-1)
to visually differentiate “every other” settings row. You'll also find a crafty uses of the adjacent selector to display forms and the focus selector to visually highlight rows for .no-js
users.
jQuery
jQuery
is used to listen to either a focus
or click
event and open the corresponding .setting-form
. Modernizr
is used to detect whether or not the device is using touch input.
Pretty lightweight, eh? Notice we aren't even having to make use of jQuery.hide()
or jQuery.show()
. Setting an .open
class on the setting row will show or hide the corresponding .setting-form
. These two <tr>
s are siblings so you may be wondering how this is accomplished using only CSS
. We have the adjacent selector to thank for this:
.settings-table tbody > tr.open + .setting-form {
display: table-row; /* display the setting form for open rows */
}
To support older browsers, we need a few more lines of jQuery
to act as a polypill for the adjacent selector.
Settings |
Value |
---|---|
site_title |
My Site |
|
|
Media Source | Filesystem |
|
|
JS–Driver | React.js 0.x |
|
|
clipsJSON |
{{"prop":"value"}} |
|
|
compress_css |
Yes |
|
Settings |
Value |
---|---|
site_title |
My Site |
|
|
Media Source | Filesystem |
|
|
JS–Driver | React.js 0.x |
|
|
clipsJSON |
{{"prop":"value"}} |
|
|
compress_css |
Yes |
|
Disqus This