1

我一直在尝试 angular 提供的 md-chips,并一直在尝试垂直堆叠它们。我查看了演示,也查看了这个答案:

垂直堆叠 md-chips angularjs

该答案的问题在于,随着更多筹码的添加,输入字段会不断移动。我希望将输入字段保持在顶部,同时将芯片堆叠在输入字段下方。有没有什么办法可以通过改变css的任何方面或在那里有另一个输入字段来完成,或者md-chips不允许这样做吗?

4

1 回答 1

0

与您提到的答案几乎相同,但与float: none;容器有关。

md-chip {
  clear: left;
}

.md-chip-input-container {
    float: none;
}

CSS 在<style>标签中,因为它需要在样式表之后加载

angular
  .module('MyApp', ['ngMaterial'])
  .controller('demoCtrl', function($scope) {

    $scope.myChips = ['AAA', 'BBB', 'CCC'];
  });
<head>
  <link rel="stylesheet" href="https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.3/angular-material.css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
  <script src="https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.3/angular-material.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js"></script>
  <style>
    md-chip {
      clear: left;
    }
    
    .md-chips {
      background-color: beige;
    }
    
    .md-chips .md-chip-input-container {
      float: none;
    }
    
    .md-chip-input-container .md-input {
      border: 1px solid black !important;
      margin-top: 8px;
    }
  </style>
</head>

<body>
  <div ng-controller="demoCtrl" ng-app="MyApp">
    <md-chips ng-model="myChips">
      <md-chip-template>
        <strong>{{$chip}}</strong>
      </md-chip-template>
    </md-chips>
  </div>
</body>

于 2017-06-08T19:41:27.180 回答