【问题标题】:ng-style and custom css propertiesng 样式和自定义 css 属性
【发布时间】:2016-12-14 14:09:28
【问题描述】:

是否可以在 ng-style 中添加自定义 css 属性,即 css 变量?

我试过用这个:

<li ng-repeat="item in vm.items" ng-style="{'--index': $index}">{{item.name}}</li>

但这不起作用我在开发者工具中检查时没有 --index in style 属性。

【问题讨论】:

    标签: javascript css angularjs css-variables


    【解决方案1】:

    不,您必须输入有效的 CSS 属性,例如

    <li ng-repeat="item in vm.items" ng-style="{'z-index': $index}">{{item.name}}</li>
    

    【讨论】:

      【解决方案2】:

      试试这个方法:

      <body ng-app="myApp" ng-controller="myCtrl">
      
      <h1 ng-style="myObj">Welcome</h1>
      
      
      <script>
      //u can put that <script> content in a separadet file
      var app = angular.module("myApp", []);
      app.controller("myCtrl", function($scope) {
          $scope.myObj = {
              "color" : "white",
              "background-color" : "coral",
              "font-size" : "60px",
              "padding" : "50px"
          }
      });
      </script>
      </body>
      

      【讨论】:

        猜你喜欢
        • 2018-04-20
        • 2021-08-10
        • 2011-01-11
        • 1970-01-01
        • 2011-12-12
        • 2015-01-23
        • 1970-01-01
        • 1970-01-01
        • 2018-05-08
        相关资源
        最近更新 更多