2016-04-28 120 views
1

我是Yii框架的新手,我想用自己的框架來實現自舉設計。Bootstrap和Yii框架

然而,關於我的自定義CSS有一個問題。

因爲我們有navbar-default爲Bootstrap中的導航欄着色。 我在我的custom.css文件中更改了我的導航欄默認顏色.navbar-default{color:red;}

很細,只有引導

現在,當我加入這Yii框架它被通過白手起家默認CSS覆蓋。我在我的Yii項目中使用鏈接引導CDN。

+0

編寫自己的'custom css'幷包含在** AssetBundle.php ** –

+0

加載第一個引導程序,然後加載您的自定義CSS工作表 – Refilon

+0

是的,我已將我的custom.css包含在appasset中,並且我已將cdn加載到我的頭部部分 –

回答

0

要確保你在yourApp/WEB目錄有一個適當的資產definitin

如:

class AppAsset extends AssetBundle 
    { 
     public $basePath = '@webroot'; 
     public $baseUrl = '@web'; 
     public $css = [ 
      'css/custom.css', 
     ]; 
     public $js = [ 
     ]; 
     public $depends = [ 
      'yii\web\YiiAsset', 
      'yii\bootstrap\BootstrapAsset', 
     ]; 
    } 

和自定義CSS在正確的目錄位置..

這樣你應該有定位在bootstrap.css鏈接下的custom.css鏈接

例如:

<title>Your Title </title> 
<link href="/your_path/frontend/web/assets/bcc5353f/css/bootstrap.css" rel="stylesheet"> 
... 
<link href="/your_path/area_web_dev/catone2.0.0-dev/frontend/web/css/custom.css" rel="stylesheet"> 

這樣的custom.css導航欄默認風格應該重寫引導的風格..

無論如何,如果你不能夠在正確的順序上你的uosoum.css放置(並確保你沒有在你的CSS文件中的錯誤),你直接這樣分配樣式導航欄小工具(所以你執行一個內聯樣式)

 NavBar::begin([ 
      'brandLabel' => $this->title = Yii::$app->name , 
      'brandUrl' => Yii::$app->homeUrl, 
      ], 
      'options' => [ 
       'class' => 'navbar-default navbar-fixed-top', 
       'style' = 'color:red;', 
      ], 
     ]); 
0

是的,我解決了這個。 我不知道我可以添加鏈接到Appassets。 因此,我只在自定義的css之前包含了Bootstrap cdn鏈接,以便custom.css覆蓋Bootstrap的默認設置。