Lieutenant General
Join Date: Mar 2011
Posts: 1,292
microsoft office 2010 pro plus key A List Apart A
It may be time consuming to make website types the two really and accessible. Specifically, laying out kinds wherever the type label and input are horizontally adjacent, as inside image beneath, can be a actual issue. We put to use to implement tables, which worked nicely on this scenario—but forms don’t constitute tabular data, so it’s a semantic faux pas. I’ve tried to create a form-styling solution that is equally available and portable (inside the sense that I can move the code from one project to the next). Floats have often provided a solution to my dilemma, but given the complexity of some layouts and the numerous float bugs associated with World-wide-web Explorer, it’s not always easy to reuse a float solution. I wanted to create something that anyone could easily reuse on any project: a style sheet that, when utilized to a correctly marked up HTML form, would provide the basis of the required layout. So here it is—my attempt at portable, available kinds. Marking up the kind The most important part of a type is the HTML we use to build it. Fortunately, HTML gives us a nice assortment of tags to build our forms in an available way. These are fieldset, legend, and label. If you are unfamiliar with these tags, here’s a brief overview: fieldset and legend The fieldset element allows us to group type controls into logical, related “chunks.” legend then allows us to add a caption to that fieldset, which helps users understand the context of the sort controls contained inside that fieldset. In some screen readers, the legend is associated with every form control in a fieldset and is read out after every tab of the keyboard, so that a individual control can always be referenced back to its legend. label The label element is used to associate information with a specific kind control, although also enforcing a code-level association between form control information and the control element itself. Let’s look at a simple fieldset example (line wraps marked » -Ed.):
Delivery Details Name* Address* Address 2 TownCity County* Postcode* Is this address also your invoice »
address?*
name="invoice-address" > Yes
name="invoice-address" > No
The HTML is quite simple, but you will notice a few things from the structure. I’m using an ordered list (ol) inside of the main fieldset. I’m doing this for two reasons: I can use each and every list item (li) as a container for each row during the sort, which is handy for styling. It is, in my opinion, semantically appropriate (i.e. a list of kind controls in some kind of logical order). Additionally, the ol provides additional information for some screen readers that announce the number of list-items when they first encounter the list. Fields that have two or more control options are nested within an additional fieldset. This logically groups the control options, as discussed above, and the legend acts as a caption for every single option within (in our case, radio inputs). Every single option is then wrapped inside of its own label tag. This is the most accessible approach, and actually aids users of assistive technologies. Styling the form The styling of the form is the fun part. My aim was to supply a main varieties style sheet that could be imported to give a kind the basic structural styling we need. Here it is. kind.cmxform fieldset margin-bottom: 10px;
sort.cmxform legend padding: 0 2px; font-weight: bold;
form.cmxform label display: inline-block; line-height: 1.8; vertical-align: top;
form.cmxform fieldset ol margin: 0; padding: 0;
kind.cmxform fieldset li list-style: none; padding: 5px; margin: 0;
sort.cmxform fieldset fieldset border: none; margin: 3px 0 0;
form.cmxform fieldset fieldset legend padding: 0 0 5px; font-weight: normal;
type.cmxform fieldset fieldset label display: block; width: auto;
type.cmxform em font-weight: bold; font-style: normal; color: #f00;
type.cmxform label width: 120px; * Width of labels *
type.cmxform fieldset fieldset label margin-left: 123px; * Width plus 3 (html space) * As you can see, the styles are very basic; those with a keen eye will notice the display property set to “inline-block” on the labels. If you are unfamiliar with “inline-block,” here’s an explanation in the W3C web site: This value causes an element to make a block box, which itself is flowed as a single inline box,office 2007 Enterprise activation , similar to a replaced element. The within of an inline-block is formatted as a block box, and the element itself is formatted as an inline replaced element. This is the magic, and the good news is that it works in World wide web Explorer for the two Windows and Mac. If you are tempted to utilize this value in other scenarios, I must point out that in Internet Explorer for Windows, it only works on elements that have a default display of “inline,” which a label does. The bad news, however, is that Mozilla-based browsers (Firefox, Netscape, etc.) do not directly support this property, but we can fix it, and I’ll come to that shortly. So, these are the core styles required to give the form its most basic appearance. I wanted to build a style sheet that contains basic type styles that act as part of a larger library of reusable style rules. In theory, they would not need to be modified by an author, but could simply be included in any website to set the baseline rules. (This core set of sort styles is the first part of my vision for creating a library of style sheets that handle the common CSS conundrums.) The best part is that authors who want to modify something like the width of the label elements, can easily overwrite the default further down from the cascade or with a more specific selector. And to truly customize every type, you can add your own styles in a separate style sheet like I have done on this “pretty” type example. Bugs As I mentioned above, users of Mozilla-based browsers won’t see what all the fuss is about. Unfortunately, Mozilla does not currently support the “inline-block” display choice, which is usually a bit of a trouble. However, Mozilla has a browser-specific display value, “-moz-inline-box”,office 2010 Standard 64 bit , which acts, for the most part, like “inline-block.” The condition with this value is that if you have a genuinely long label, the text disappears below the adjacent kind control. Text does not wrap inside of an element displayed as “-moz-inline-box.” But if we location the label text inside an element displayed as “block” inside the “-moz-inline-box” element and give it a width,microsoft office 2010 pro plus key , it behaves as it should. Adding all that by hand into the document is going to mess up our nice, lean, mean HTML —plus we could possibly decide to change the form layout later, and who wants the extra markup in there? Luckily,windows 7 enterprise serial key , there’s an easy way to fix this using JavaScript and the DOM (line wraps marked » -Ed.): if( document.addEventListener ) »
document.addEventListener( 'DOMContentLoaded', cmxform, false); function cmxform(){ Hide forms $( 'form.cmxform' ).hide().end(); Processing $( 'form.cmxform' ).find( 'lilabel' ).not( '.nocmx' ) »
.each( function( i )var labelContent = this.innerHTML; var labelWidth = document.defaultView. »
getComputedStyle( this, '' ).getPropertyValue( 'width' ); var labelSpan = document.createElement( 'span' ); labelSpan.style.display = 'block'; labelSpan.style.width = labelWidth; labelSpan.innerHTML = labelContent; this.style.display = '-moz-inline-box'; this.innerHTML = null; this.appendChild( labelSpan ); ).end(); Show types $( 'form.cmxform' ).show().end();
} The JavaScript uses the wonderful JQuery library (which also, obviously, needs to be included) to simplify the processing. I will briefly explain how this works. Firstly, I hide any type that uses the “cmxform” class. Hide forms
$( 'form.cmxform' ).hide().end(); We do this because otherwise the user may possibly see the type “fixing” itself as it renders in the page, which can look a bit strange. Secondly, using the JQuery methods and a combination of CSS selectors and XPath, I collect all labels that are a direct descendant of an li,office 2007 Pro Plus key , that do not have a class of “nocmx”. $( 'form.cmxform' ).find( 'lilabel' ).not( '.nocmx' ) »
.every single( function( i ){
... The reason I use the “nocmx” filter is so that users can add that class to labels that require a different styling. This can be very useful, as I have discovered from using this method for a while. Then, for each collected label, a span is created inside to fix the “inline-block” problem. $( 'form.cmxform' ).find( 'lilabel' ).not( '.nocmx' ) »
.each( function( i )... Finally, all the originally hidden varieties are designed visible again, and everything looks sweet. Show varieties
$( 'form.cmxform' ).show().end(); Note: I’m using the Mozilla-specific document.addEventListener() method to launch the script. This essentially is ideal, as it only runs for Mozilla (which is all we need) and it launches as soon as the DOM has been loaded. Although JavaScript could possibly not appear the most elegant solution, it is completely unobtrusive and, when JavaScript is disabled, the kind degrades gracefully. There’s also a small amount of tidying up to do in Web-based Explorer though. For Windows, we need to tweak the positioning of the legend@s so they line up neatly. This might be achieved by giving the @legend a negative leftright margin as shown below: form.cmxform legend padding: 0 2px; font-weight: bold; _margin: 0 -7px; * IE Win * For IE5Mac, we need to tweak the display of the legend, to fix an odd display bug, by adding the following: *\**
kind.cmxform legend display: inline-block;
* IE Mac legend fix * This rule allows us to supply a rule specially to Online Explorer for Mac. If you are uncomfortable in using browser specific rules during this way, feel free to remove them. You could add these fixes to browser-specific style sheets, but I wanted this technique to be as portable as possible, so all the styles are in one put. Finishing up We’re done. All you need to do is include the relevant “cmxform” files and then add the class of “cmxform” to any type you need to. (If you are wondering where the name “cmxform” came from, it’s there because I developed this technique though working for Cimex Media in London.) Enjoy! Note: This form technique has been tested with Safari 2.0.3, Firefox 1.5, Opera 8.5, World-wide-web Explorer 7b2 , Net Explorer 6, Internet Explorer 5 (Windows), Word wide web Explorer 5.2 (Macintosh), Netscape 7.2 (Macintosh), and Netscape 8.1 (Windows).