1

As a newbie,I study Yii two weeks.At the time,I have a question: we all know,Yii provide a CHtml class,so we can create the view rapidly and convinently. but how can I customize the style if I do not want to use the defalut style?

Chain
  • 37
  • 1
  • 8
  • CHtml has not much to do with any default style. It's only a static class that helps you to render certain HTML elements. Please clarify what you mean. – Michael Härtl Sep 17 '13 at 06:28
  • Possible dupe: http://stackoverflow.com/questions/1998449/include-css-javascript-file-in-yii-framework – ernie Sep 17 '13 at 21:11

2 Answers2

1

Depends what you mean by default style.

If you want to add extra html options you can use the optional $htmlOptions param in CHtml functions.

Eg to add a custom style to a text field you do something like:

echo Chtml::textField('mytextfield', 'defaultvalue', array('style' => 'color: green;'))
Rowan
  • 598
  • 5
  • 7
  • I already know this way,thank you very much!I want to know if i can load a external css file... thanks in advance! – Chain Sep 17 '13 at 04:14
1

Modify the layout file, and insert an external CSS stylesheet.

protected/views/layouts/main.php

<head>
    <link rel="stylesheet" type="text/css" 
          href="<?= Yii::app()->getBaseUrl(true) ?>/css/stylesheet.css" />
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • In the layout, a static load might be okay, but in general (i.e. if you want to use it in a view), I'd suggest using the [registerCssFile() method](http://www.yiiframework.com/doc/api/1.1/CClientScript#registerCssFile-detail) – ernie Sep 17 '13 at 21:10