Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 2 min read

Support

Using CSS to Align Form Fields

Forms are much easier to use if they are aligned. This example uses CSS table structures to align our form. It turns groups into tables, inputs into rows and labels and values into cells.

Address Aligned

Program

xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms">

Address Form Aligned Using CSS
type="text/css">
/* a stylesheet for X-Forms input field alignment */

@namespace xf url("http://www.w3.org/2002/xforms");

/* give the input form labels and the fieldset legend a bold sans-serif font */
label, legend {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}

/* give the fieldset some breathing room */
fieldset {
padding: 5px;
width: 260px;
}

/* the labels are right-aligned in a 150px wide column */
xf|label {
width: 150px;
margin: 3px;
text-align: right;
}

/* the input values are left aligned */
xf|value {
text-align: left;
}

/* vertical area between input boxes */
input {
margin: .2em;
}

/* each group is our table */
xf|group {
display: table;
}

/* each input is a row in the group table */
xf|input {
display: table-row;
}

/* each label within an input is a cell in the input row */
xf|input xf|label {
display: table-cell;
}

/* each value (pseudo-element) is also a cell in the input row */
xf|input::value {
display: table-cell;
}
]]>

xmlns="">

/>
/>
/>
/>
/>

Mailing Address
ref="LocationStreetFullText">
Street:

ref="LocationStreetFullText2">
/>

ref="LocationCityName">
City:

ref="LocationStateName">
State:

ref="LocationPostalID">
Postal Code:

Discussion

This style sheet only covers the XForms tags. It will need additions if you want to align select, select1, textarea and other controls. A full CSS file for doing this is described later on in this cookbook.

Note that you MUST put inputs inside of a group element for this stylesheet to work.

Also note that the table can grow if the labels get too long.

Note that the display: table properties work in FireFox but may not work in older browsers that do not support table layout.

Alternative layout strategy using float:left

You can control the width of the label column by the odd interaction of the float:left CSS control and the block display. Basically if you try to control
the width of a block it may not work unless you also add the float:left to label.

Here is the CSS that works for this:

/* This line ensures all the separate input controls appear on their own lines */
xf|input, xf|select, xf|select1, xf|textarea {display:block; margin:5px 0;}

/* Makes the labels right aligned in a 250px wide column that floats to the left of the input controls. */
xf|input > xf|label, xf|select > xf|label, xf|select1 > xf|label, xf|textarea > xf|label
{text-align:right; padding-right:10px; width:250px; float:left; text-align:right;}

Note that some older browsers do not support the child (greater than) selector correctly.

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
This example has been tested using the FireFox browser. The use of the .xf-value class selector may not work on other systems.
CC BY-SA 4.0
This example uses a CSS style sheet to put the labels and fieldset legend in bold and align the login and password labels. By default the fieldset box stretches the entire width of the page. You can make it static by adding a style attribute with the width set to 250 pixels like this:
CC BY-SA 4.0
There are three message options: - **ephemeral** - a message that just appears briefly and goes away by itself - **modeless** - a message you can ignore for now - **modal** - a message the user must acknowledge before you go on ## Screen Image Here is a sceen image with the ephemeral message showing
CC BY-SA 4.0
lang="css"> textarea { font-family: sans-serif; height: 8em; width: 600px; } == Sample Program == lang="xml"> xmlns=" xmlns:xf=" XForms textarea xmlns=""> /> ref="Name" incremental="true"> Name: </xf:output ref="Name"> ref="MyTextValue"> Note: ## Discussion One of the challenges is to be able to for
CC BY-SA 4.0
The example includes the default textarea and a small, medium, large and extra large version. Note that if the content exceeds the textarea a scroll bar is automatically added to the control. ![Textarea styled with CSS]( Textarea styled with CSS (Image: Juanecca, CC BY-SA 3.0) ## Sample Program xmln
CC BY-SA 4.0
But in that case a series of space-delimited values is stored in the value associated with the control. ## Screen Image ![Boolean Checkbox Using Input Control]( Boolean Checkbox Using Input Control (Image: The original uploader was Dmccreary at English Wikibooks ., CC BY-SA 3.0) ## Link to XForms Ap