Yii CHtml::radioButtonList - CSS to align horizont

2019-02-22 11:44发布

问题:

I am using yii framework for my development . I wrote CSS and able to align my <input tags in html properly and I am using the same CSS for yii and the alignment is messed up . Could some help me on this ?

I wanted it to be displayed like below

Here is the yii code I have

<div id="gender">
        <label>Gender :</label>
        <?php echo CHtml::radioButtonList('gender_code','',array('Male'=>'Male','Female'=>'Female'),array('separator'=>'')); ?>
    </div>

CSS

 <style type="text/css">          
           div#gender {
                    margin-top:20px;
                    margin-left:200px;
           }      

           div#gender label
           {
                   font-weight: bold;
                   font-size: 0.9em;
                   float:left;
                   margin-left:2px;
                   text-align:left;
                   width:100px;
            }

</style>

and it is coming as below image

回答1:

Looks like you might need

div#gender input
{
    float:left;
}


回答2:

<?php echo CHtml::radioButtonList('gender_code','',array('Male'=>'Male','Female'=>'Female'),array(
    'labelOptions'=>array('style'=>'display:inline'), // add this code
    'separator'=>'',
)); ?>


回答3:

add this css code somewhere (to the end of css/main.css, for example):

input[type=radio] + label, input[type=checkbox] + label { display:inline !important; }