PForm is a pixel perfect CSS form layout library.
See http://sciactive.com/pform/ for examples.
You can install PForm with NPM, Composer or Bower.
npm install pformcomposer require sciactive/pformbower install https://github.com/sciactive/pform.gitPForm comes with the following files:
pform.css- The main stylesheet.pform-bootstrap.css- Use this if you also use Bootstrap.pform-ie-lt-8.css- Use this to support Internet Explorer 6 and 7.pform-ie-lt-6.css- Use this to support Internet Explorer 5.01 and 5.5.
So here's how you'd include them all:
<linkhref="pform.css" media="all" rel="stylesheet" type="text/css" /><!-- Include this file if you are using Bootstrap. --><linkhref="pform-bootstrap.css" media="all" rel="stylesheet" type="text/css" /><!--[if lt IE 8]><link href="pform-ie-lt-8.css" media="all" rel="stylesheet" type="text/css" /><![endif]--><!--[if lt IE 6]><link href="pform-ie-lt-6.css" media="all" rel="stylesheet" type="text/css" /><![endif]-->Notice the conditional comments to serve older versions of IE the right files. If you have to support older versions of IE, PForm can do it.
Now you can use PForm like this:
<formclass="pf-form" action="#" method="post"><divclass="pf-element pf-heading"><h3>Login</h3></div><divclass="pf-element"><label><spanclass="pf-label">Username</span><inputclass="pf-field" type="text" name="username" /></label></div><divclass="pf-element"><label><spanclass="pf-label">Password</span><inputclass="pf-field" type="password" name="password" /></label></div><divclass="pf-element"><label><spanclass="pf-label">Remember Me</span><spanclass="pf-note">Lasts for 2 weeks.</span><inputclass="pf-field" type="checkbox" name="remember" /></label></div><divclass="pf-element pf-buttons"><inputclass="pf-button" type="submit" name="submit" value="Submit" /><inputclass="pf-button" type="reset" name="reset" value="Reset" /></div></form>Here's the same form, built with a fieldset:
<formclass="pf-form" action="#" method="post"><fieldset><legend>Login</legend><divclass="pf-element"><label><spanclass="pf-label">Username</span><inputclass="pf-field" type="text" name="username" /></label></div><divclass="pf-element"><label><spanclass="pf-label">Password</span><inputclass="pf-field" type="password" name="password" /></label></div><divclass="pf-element"><label><spanclass="pf-label">Remember Me</span><spanclass="pf-note">Lasts for 2 weeks.</span><inputclass="pf-field" type="checkbox" name="remember" /></label></div><divclass="pf-element pf-buttons"><inputclass="pf-button" type="submit" name="submit" value="Submit" /><inputclass="pf-button" type="reset" name="reset" value="Reset" /></div></fieldset></form>PForm has two different layout options, Inline (default) and Block. To use block layout for an entire form, add the pf-layout-block class to the pf-form element. To use block layout for an individual element, add the pf-layout-block class to a pf-element element.
<divclass="pf-element pf-heading"><h3>Sign Up Now</h3><p>You will receive 200 bonus points just for signing up!</p></div><spanclass="pf-required">*</span>You can also mark the element as completed (with JavaScript validation) by adding the pf-completed class, like so:
<spanclass="pf-required pf-completed">*</span>The best place I've found to put these is right after a label's text, like this:
<spanclass="pf-label">Username <spanclass="pf-required">*</span></span>You can put the pf-completed class on the pf-element element instead, to mark any required asterisks in that element as completed.
Sometimes you will need to group fields so they don't fall left below the label. You can do this by wrapping them in a pf-group element:
<divclass="pf-element"><spanclass="pf-label">Favorite Food</span><divclass="pf-group"><label><inputclass="pf-field" type="radio" name="radiotest" /> Hot Dogs</label><br/><label><inputclass="pf-field" type="radio" name="radiotest" /> Hamburgers</label><br/><label><inputclass="pf-field" type="radio" name="radiotest" /> Cheeseburgers</label><br/><label><inputclass="pf-field" type="radio" name="radiotest" /> Sushi</label><br/><label><inputclass="pf-field" type="radio" name="radiotest" /> Pizza</label><br/>
...
</div></div>Remember that you can use the pf-group class on a span instead. This lets you put a group inside a label element and have it validate.
Fieldset groups must use the pf-group class:
<fieldsetclass="pf-group"><legend>Household</legend><divclass="pf-element"><label><spanclass="pf-label">Household Memebers</span><spanclass="pf-note">Family members living in your house.</span><inputclass="pf-field" type="text" name="household" /></label></div></fieldset>Labels can be aligned left (default) or right. To align them, use the pf-labels-left and pf-labels-right classes. You can put these classes on a pf-form element, pf-group fieldset, pf-element element, or pf-label element. You can override an ancestor's alignment class too.
Elements can be extended to the form's width using the pf-full-width class:
<divclass="pf-element pf-full-width"><label><spanclass="pf-label">Comments</span><spanclass="pf-group"><spanclass="pf-field"><textareastyle="width: 100%;" name="comments" rows="5" cols="30"></textarea></span></span></label></div>You can apply a form like layout to verification pages by simply providing no inputs:
<formclass="pf-form" action="#" method="post"><fieldset><legend>Verify this Information</legend><divclass="pf-element"><spanclass="pf-label">Name</span><spanclass="pf-field">Jake Sully</span></div><divclass="pf-element"><spanclass="pf-label">Location</span><spanclass="pf-note">This will not be displayed to visitors.</span><spanclass="pf-field">Pandora.</span></div><divclass="pf-element"><spanclass="pf-label">Species</span><spanclass="pf-field">N/A</span></div><divclass="pf-element pf-buttons"><buttonclass="pf-button" type="submit" name="submit">Correct</button><buttonclass="pf-button" type="button" name="changes">Make Changes</button></div></fieldset></form>