问题
i am newbie in Cakephp trying to create a space between radio box and a label
<span class="label"><b>Gender</b></span>
<?php $options=array('M'=>'Male'."<br>" , 'F'=>'Female');
$attributes=array('legend'=>false,'label'=>'gender_male.','class'=>'radio');
echo $this->Form->radio('gender',$options,$attributes);?>
</div>
i have created a radio box in Cakephp but there is no space between the box and label is coming ... how can i create a space .
回答1:
Try it
<span class="label"><b>Gender</b></span>
<?php
$options=array('M'=>' Male'."<br>" , 'F'=>' Female');
$attributes=array('legend'=>false,'label'=>'gender_male.','class'=>'radio');
echo $this->Form->radio('gender',$options,$attributes);?>
</div>
回答2:
Adding margin or padding to one of the elements depending on your design goals.
This is not a CakePHP issue but a CSS styling task. See http://www.w3schools.com/css/
回答3:
You can simply use the following code:
<style type="text/css">
label{padding-left:5px;}
</style>
<span class="label"><b>Gender</b></span>
<?php $options=array('M'=>'Male'."<br>" , 'F'=>'Female');
$attributes=array('legend'=>false,'label'=>'gender_male.','class'=>'radio', 'div' => false, 'separator' => '');
echo $this->Form->radio('gender',$options, $attributes);?>
回答4:
You can use labels in styled span with padding but don't forget to use escape False otherwise it will show you the entire span. Please see the <span style="padding:0 15px 0 15px;">No</span>
part of the code.
<?php
echo $this->Form->radio('lifestyle_drinking',
[
[ 'value' => '0', 'text' => '<span style="padding:0 15px 0 15px;">No</span>'],
[ 'value' => '1', 'text' => 'Yes'],
[ 'value' => '2', 'text' => 'Ocassionally']
],
[ 'div' => false,
'class' => 'form-control col-xs-10 col-sm-10',
**'escape' => false**
]);
?>
来源:https://stackoverflow.com/questions/17429404/space-between-the-radio-button-and-label-cakephp