<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 6 年前。
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 6 年前。
我有一个带有 text-align:center
的 div。
在 div 中我有一个 span
。
在 fiddle 中你可以看到输出1,2 3,等等
它是float:left
,所以我在一行中得到它的输出。
但在 div 内部它不遵循样式 text-align:center
。
如果我删除 float left,输出将在不同的行中,但文本将居中对齐。
我需要在一行中输出所有内容,并且它应该与 div
的中心对齐。
function TodoCtrl($scope) {
$scope.col = ['1', '2', '5', '8'];
$scope.cols = ['1', '2', '5', '8'];
}
.ll {
text-align: center;
}
p {
float: left;
}
<div ng-repeat="c in size">
<span ng-repeat="m in p.size" ng-if="m == c.id">
<a href="" ng-click="select_size(c.id)"
ng-class="{gvborder : allsels == c.id}">
<p style="text-align:center; float:left"> {{c.name}} </p>
</a>
</span>
</div>
我的 fiddle 是 here
最佳答案
你只需要设置你的 <span>
至 display:block
在做之前 text-align:center;
自 <span>
是display: inline
默认情况下。
Here's another answer详细介绍了该主题。
关于html - 循环内的div文本对齐中心问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37925745/
相关文章:
javascript - 通过单击另一个 div 更改 div 中的数据
html - CSS float 布局的最佳或推荐用途是什么?
angularjs - 单击导航栏下拉菜单时 ngView 消失
html - 如何制作比屏幕尺寸宽的表格,可滚动并保持标题行固定?
angular - CSS - 如何修复一个部分和其他移动?
javascript - 使用 JavaScript 和 TypeScript 进行 Angular 1 依赖注入(inject)
javascript - 如何创建从不读取 $scope 的 $scope 函数?