Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态地将div(div no总是非常从0到100)插入到固定大小的div:Angularjs中_Javascript_Angularjs - Fatal编程技术网

Javascript 动态地将div(div no总是非常从0到100)插入到固定大小的div:Angularjs中

Javascript 动态地将div(div no总是非常从0到100)插入到固定大小的div:Angularjs中,javascript,angularjs,Javascript,Angularjs,我有一个固定大小的div,其中动态div将使用ng repeat。内幕股的方式就像如果只有一个股来,那么它的大小(高度和宽度)应该是100%。如果是2,那么是25%。这是我想要的截图。请看一下。提前谢谢 您可以尝试添加ng类,并根据您的div数更改类 首先用容器创建不同的css类 CSS .container{ width:400px; height:400px; border:solid 1px black; } /* use for all child */ .child{

我有一个固定大小的div,其中动态div将使用ng repeat。内幕股的方式就像如果只有一个股来,那么它的大小(高度和宽度)应该是100%。如果是2,那么是25%。这是我想要的截图。请看一下。提前谢谢


您可以尝试添加ng类,并根据您的div数更改类

首先用容器创建不同的css类

CSS

.container{
  width:400px;
  height:400px;
  border:solid 1px black;  
}

/* use for all child */
.child{
  display:inline-table;
}

/*For 2x2 */
.deux{
  background-color:red;
  width:50%;
  height:50%;
}

/* 3x3 */
.trois{
  background-color:blue;
  width:33.3%;
  height:33.3%;
}

/* 4x4 */
.quatre{
  background-color:yellow;
  width:25%;
  height:25%;
}
HTML

<div class="container">
       <div  ng-repeat="x in i" class="child" ng-class="{'deux':(i.length<=4),'trois':(i.length>4 && i.length<=9),'quatre':(i.length>9)}">
       {{x}}
       </div>
  </div>

{{x}
您可以尝试更改我的示例中的数组:

CSS

.big{

     height: 300px;
     width: 300px;
     overflow: auto;
     background: #DAE8ED;
}

控制员

app.controller('Ctrl', function($scope){

  $scope.numbers = [1,2,3,4,5,6,7];
  var width = 300/Math.ceil(Math.sqrt($scope.numbers.length)) + 'px';
  $scope.customStyle={'height':width, 'width':width};
});
HTML



你的问题是什么?请在您的问题中包含代码。您是否有一个最大div数,或者它可以是无限的?只有3种不同的尺寸吗?
app.controller('Ctrl', function($scope){

  $scope.numbers = [1,2,3,4,5,6,7];
  var width = 300/Math.ceil(Math.sqrt($scope.numbers.length)) + 'px';
  $scope.customStyle={'height':width, 'width':width};
});
<body ng-controller='Ctrl'>
    <div class='big'>
     <div class='small' ng-repeat="n in numbers" ng-style='customStyle'></div>
</div>