Buttons without class
Buttons shouldn't need classes to function. Clean up your act (and your code) with some HTML!
But why?
Everytime I ask people why they use div
's or a
's for their buttons, the default response is something like Because it's easier to style
. This page shows Bootstrap's buttons styled via some standard HTML and a bunch of CSS selectors. Moreover, they don't use classes.
The used CSS properties are—as I copied them—almost identical to those of Bootstrap. The only thing I changed is some inherited font stuff on the default button
declaration. Most of the work went into a clean-up of the selectors.
But how?
To pull this nifty trick off I used this great CSS framework called Cool Semantic Styles (previously know as Cascading Style Sheets). This revolutionary technique uses information that is built into HTML itself—believe it or not—to turn it into styles. Who knew you could set a disabled
attribute on a button
and style it accordingly?
When I first discoverd this technique I was blown away. It took me several years to recover from the overwhelmed feeling of happyness—I'm not really sure I have recovered to be honest.
But, but, how?
Don't worry, I know the feeling, I've been there! It will all come together once you start with Cool Semantic Styles. Just try it out; it's built into every browser.
This sounds great, what is the catch?
Okay, there is this one itsy bitsy tiny little thing: support pre Internet Explorer 7 is pretty bad; Internet Explorer 6 and earlier don't allow you to select states in your Cool Semantic Styles documents.
So buttons? What about everything else?
I know Cool Semantic Styles seems limited at this time, but I teamed up with major browser vendors like Mozilla, Apple, and Microsoft to add support for more design patterns soon. Even the W3C and its WAI-ARIA initiative are on board!
Thoughts during development
Buttons are not links, so I will not include styles for it.
I copied Bootstraps base colours, but kept the text dark, because white on these backgrounds (as is the default) does not have enough contrast.
Bootstrap's disabled styling isn't the best, but I kept it for consistency's sake.
Could have used a mixin to do the styles, as they are just repetitions, but I feel it is important to see what is happening in an example. And see the madness we create when we style this many buttons.
We could have used :matches()
if it wasn't for those pesky Edge fellers.
What exactly is a success button? When do you get a success button? And what should it convey? Who came up with this?! This version of Cool Semantic Styles uses a My inferior knowledge was proven again by the artist (and jQuery Standards Dude) Brian Kardell. We can use the form
with an aria attribute aria-invalid
that has a value of false
. I"m not sure this is the right approach for this, but as soon as someone tells me what a success button is, I'll change it.:valid
pseudo-class to check the validity of a form and thus mark a button as a success, or something. Still not sure what a success button does. Anyway, this works a treat!
The current “info”-button uses a standard button
with a aria-owns
pointed at an element with an id
that starts with “modal-”. I'm not saying that all modal triggering buttons are info buttons, but it seemed like a good thing at the time. If you have any suggestions, suggest away!
I skipped Bootstrap's warning style button. As I'm not sure what it's used for and how it's different from a danger button. I'm sure that if it's distinct from the danger button, there is distinct HTML around it.