如何水平而不是垂直排列单选按钮?
我一直在查看 Cookbook - 7.3.3 Automagic Form Elements试图找到一种让单选按钮水平排列而不是垂直排列的方法。我一直在看 'div' =>; 'class_name' $options
也是 $options[' Between']
、 $options['separator']
和 $options['after' ]
但没有成功。有没有一种“蛋糕”的方式来做到这一点?
<?=$form->input('Product Type', array(
'type' => 'radio',
'id' => $tire['ProductType']['id'],
'name' => $tire['ProductType']['id'],
'options' => array(2=>'Tire Manufacturer', 7=>'Rim Manufacturer '),
));?>
等价于此
<label>Product Type</label>
<div style="padding-top:5px;">
<input type="radio" name="data[Manufacturer][product_type_id]" value="<?=$tire['ProductType']['id']?>"> Tire Manufacturer
<input type="radio" name="data[Manufacturer][product_type_id]" value="<?=$wheel['ProductType']['id']?>"> Rim Manufacturer
</div>
I have been looking at the Cookbook - 7.3.3 Automagic Form Elements trying to find a way for radio buttons to line up horizontally rather than vertically. I have been looking at the 'div' => 'class_name' $options
also the $options[‘between’]
, $options[‘separator’]
and $options[‘after’]
but have been unsuccessful. Is there a "cake" way of doing this?
<?=$form->input('Product Type', array(
'type' => 'radio',
'id' => $tire['ProductType']['id'],
'name' => $tire['ProductType']['id'],
'options' => array(2=>'Tire Manufacturer', 7=>'Rim Manufacturer '),
));?>
The of equivalent this
<label>Product Type</label>
<div style="padding-top:5px;">
<input type="radio" name="data[Manufacturer][product_type_id]" value="<?=$tire['ProductType']['id']?>"> Tire Manufacturer
<input type="radio" name="data[Manufacturer][product_type_id]" value="<?=$wheel['ProductType']['id']?>"> Rim Manufacturer
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这对我有用:
在视图文件 (viewfile.ctp) 内:
确保在属性中设置了 'label'=>false 和 'legend'=>false。
在你的样式表中:
由于 input[type=radio] 的默认 CakePHP 样式规则(在 app/webroot/css/cake.generic.css 内),我永远与之斗争文件)始终优先。我生成了另一条规则,通过引用表单以及附加有类名的无线电输入规则来专门挑选出有问题的无线电组(form#changeRegionStdForm input[type=radio].locRad)。我最初使用 input[type= 之前列出的 form# 规则来执行此操作。只有当我将其移动到input[type=之后,单选按钮才会水平排列。
我希望这是有道理的,并且能够真正帮助别人。
This works for me:
Inside your view file (viewfile.ctp):
Make sure 'label'=>false and 'legend'=>false are set in your attributes.
In your stylesheet:
I fought this forever because of the default CakePHP style rule for input[type=radio] (inside the app/webroot/css/cake.generic.css file) was always taking precedence. I generated another rule to specifically pick out the radio group in question by referencing the form along with the radio input rule appended with the class name (form#changeRegionStdForm input[type=radio].locRad). I initially did this with the form# rule listed before the input[type=. Only when I moved it after the input[type= did the radio buttons line up horizontally.
I hope this makes sense and actually helps someone else.
最简单的方法是将每个单选按钮放在“LI”标签内,然后将 CSS 样式应用于“UL”,告诉它水平显示“LI”标签,而不是垂直显示。您可以在此处找到很多水平列表设计。
The easiest way to do this is to put each radio button inside an 'LI' tag, and then apply CSS styles to the 'UL' that tells it to show 'LI' tags horizontally instead of vertically. You can find a lot of horizontal list designs here.
我很晚才发现这个帖子。但我认为其他人可能会像我现在一样偶然发现这一点。
尝试这样的操作:
现在设置 id hMenu 的样式。那应该可以解决这个问题。
这没有任何样式提供了垂直的单选按钮。但如果你在 ul 和 li 上使用 css 样式,你实际上可以让它倒立! :)
I found this post very late. But i thought others might stumble upon this like i did now.
Try something like this:
Now style the id hMenu. That should solve this problem.
This without any styling gives verical radio buttons. But if you use css styling on ul and li you could literally make it stand on its head! :)
使用这个:
结果如下:
use this:
which result look like this :
试试这个,我的代码通过这个工作了..
在样式表中添加以下内容..
Try this, I got my code working through this..
in the style sheet add the following..
你像这样关注:
You an follow like this :