位置<form:radiobuttons>垂直</form:radiobuttons>

时间:2013-08-14 09:43:08

标签: html css jsp spring-mvc

我正在使用Spring MVC <form:radiobuttons>来显示单选按钮:

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

但是,它会水平显示它们。生成的HTML如下:

<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>

如何垂直显示它们?

3 个答案:

答案 0 :(得分:6)

您可以将默认包装器(<span>)更改为您可以更好地操作的其他内容,例如<li>

您可以使用element属性更改包装器:

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

然后,只需要根据自己的需要设计样式:

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

...

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

答案 1 :(得分:1)

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

只是一些建议,它取决于情况,有时只能使用元素&#34; br&#34;,而不需要额外的css。

答案 2 :(得分:1)

另一种解决方案,没有额外的css文件

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