我正在使用AngularJS和Bootstrap,并具有以下结构:
Data grid with many columns
我希望我的flexible-width-component
伸展能够自动填补它自身和它之间的空隙fixed-width-component
,因为任何分辨率都比它宽1200px
.两个组件都需要彼此相邻显示.
任何建议非常感谢!
您可以获取父容器offsetWidth
并从中减去固定宽度:
var example = angular.module('exmp', []); example.directive('flexibleWidth', function() { return function(scope, element, attr) { // Get parent elmenets width and subtract fixed width element.css({ width: element.parent()[0].offsetWidth - 400 + 'px' }); }; });
这里的 a demo