nuttynibbles nuttynibbles - 1 year ago 74
CSS Question

Position <form:radiobuttons> vertically

I'm using Spring MVC

to display radio buttons:

<form:radiobuttons path="selection" items="${arraySelection}" />

However, it displays them horizontally. The generated HTML is as follows:

<input id="selection1" type="radio" value="0"" name="selection">
<label for"selection1">Off</label>
<input id="selection2" type="radio" value="1"" name="selection">
<label for"selection2">On</label>

How do I display them vertically?

Answer Source

You could change the default wrapper (which is <span>) to something else that you can manipulate better, like <li> for example.

You can use the element attribute to change the wrapper:

  <form:radiobuttons path="selection" items="${arraySelection}" element="li" />

It's then just a matter of styling it how you want:

ul.verticalRadios {
  list-style-type: none;
  /* or whatever */


<ul class="verticalRadios">
  <form:radiobuttons path="selection" items="${arraySelection}" element="li" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download