Changing Position Of Labels

How can I change position of label in main menu. For example ‘Home’, ‘About’ label appears on left hand side while I want some other label appear on right side. How can I achieve this.

What class are you using for your menu? CMenu? Maybe you just need to reorder the items in the ‘items’ option array?

I am using CMenu. Reordering will only change the order. What if I want display the label for example ‘Home’ on extreme right while all other labels are on left side?

I don’t think this is possible in CMenu. I would try using two CMenu’s and position them using CSS.

You can add class CSS using htmlOptions when you create Menu like:


//in your view

$this->widget('zii.widgets.CMenu', array(

    'id'=>'myMenu',

    'items'=>$this->myMenu,

    'htmlOptions'=>array('class'=>'right-position'),

));

Yii will render like:


...

<ul class="right-position" id="myMenu">

...

</ul>

...

And You’re able to define Css for right-position class like:


.right-position

{

  text-align: right;

}



So Your Menu-Items should be on the right-side.

More info: If you want apply CSS for each Menu-Item in the different ways, you can use itemOptions and linkOptions for this. For example:


//At your controller

$this->myMenu = array(

'id'=>'myMenu',

'items'=>array(

    array(

        'label'=>'Home',

        'url'=>array('site/index'),

        'itemOptions'=>array('class'=>'css-item'),

        'linkOptions'=>array('class'=>'css-link'),

    )

),

);

Yii will render like:


...

<ul id="myMenu">

    <li class="css-item">

        <a class="css-link" href="/site/index">Home</a>

    </li>


...

For example: If you want Home item on the right-side the you can define css-item like:


.css-item

{

  float: right;

}

I hope it’s helpful for you.

Thanks you have answered my question in stackoverflow.