Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position <form:radiobuttons> vertically

I'm using Spring MVC <form:radiobuttons> to display radio buttons:

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

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

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

How do I display them vertically?

like image 281
chrizonline Avatar asked Jul 10 '26 07:07

chrizonline


1 Answers

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:

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

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" />
</ul>
like image 146
Bogdan Avatar answered Jul 11 '26 21:07

Bogdan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!