如何/在哪里添加angularJS中的CSS代码

时间:2016-11-16 07:00:06

标签: css angularjs angular-material

我正在尝试使用AngularMaterial构建一个对话框,并在演示中它有css代码:

.dialogdemoBasicUsage #popupContainer {
  position: relative; 
}

.dialogdemoBasicUsage .footer {
  width: 100%;
  text-align: center;
  margin-left: 20px;
}

.dialogdemoBasicUsage .footer, .dialogdemoBasicUsage .footer > code {
  font-size: 0.8em;
  margin-top: 50px; 
}

.dialogdemoBasicUsage button {
  width: 200px; 
}

.dialogdemoBasicUsage div#status {
  color: #c60008; 
}

.dialogdemoBasicUsage .dialog-demo-prerendered md-checkbox {
  margin-bottom: 0; 
}

在我的angularJS项目中 - 我在哪里放这个代码?我创建一个新的.css文件,然后引用它,我是否必须在它周围放置任何东西?

2 个答案:

答案 0 :(得分:2)

与在普通HTML应用程序中执行此操作的方式相同。

将css代码添加到名为style.css的文件中,在

中引用它
<head>
  <title>To Do List</title>
  <link href="style.css" rel="stylesheet" />
</head>

<强> DEMO

答案 1 :(得分:1)

在正常使用情况下,您应该包含库附带的CSS文件。

通过材质CSS的user guide,您应该将这些文件包含在HTML

<html lang="en" >
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Angular Material style sheet -->
  <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.css">
</head>
<body ng-app="BlankApp" ng-cloak>
  <!--
    Your HTML content here
  -->  

  <!-- Angular Material requires Angular.js Libraries -->
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js"></script>

  <!-- Angular Material Library -->
  <script src="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.js"></script>

  <!-- Your application bootstrap  -->
  <script type="text/javascript">    
    /**
     * You must include the dependency on 'ngMaterial' 
     */
    angular.module('BlankApp', ['ngMaterial']);
  </script>

</body>
</html>

<!--
Copyright 2016 Google Inc. All Rights Reserved. 
Use of this source code is governed by an MIT-style license that can be in foundin the LICENSE file at http://material.angularjs.org/license.
-->

如果您需要在CSS之上进行进一步修改,请创建一个新的CSS文件并将其包含在<head>

中的angular-material CSS文件下面