Easy Enyo Checkbox Labels

In a recent Enyo project I needed a labeled vertical group of checkboxes for setting the app’s preferences. I was hoping that I could just put a bunch of onxy.Checkbox components from Enyo’s Onxy widget library inside a Group component and use the content property of each checkbox as its label. This is the code:

Unfortunately, the results weren’t quite what I expected:

checkboxes-nocss

The content text was displayed inside the checkbox and the checkboxes were positioned horizontally instead of vertically. Happily, just a little bit of CSS solved the problem:

With the above CSS, the checkboxes were displayed just as I was expecting:

checkboxes-css

So, how does it work? An Onyx checkbox is just a DIV tag with a background image which displays its state (checked or unchecked). First, we set each checkbox to display:block so that it appears on its own line. Next we give it a width:auto so that it takes up the entire width of its containing element. To get the label text (the checkbox’s content property) out of the checkbox itself, we use padding-left to move the text to the right. to vertically center the text, we set the line-height to the height of the checkbox.

While we’re playing around with the CSS, we’ll add some margins to give some extra space between the checkboxes and the containing element.

A nice side effect is that the user can tap on the label as well as the checkbox to select it since the checkbox DIV is now the width of the containing element.

Tested in Windows on Chrome version 25, Firefox version 19 and IE 10 and on Android Chrome version 25.

Tags: , , , , , ,

This entry was posted on Tuesday, March 5th, 2013 at 9:44 pm and is filed under mobile, projects, web. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Easy Enyo Checkbox Labels”

  1. Doug Reeder Says:

    March 6th, 2013 at 8:48 pm

    Straightforward and useful – nice!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Dragongears news RSS feed