[英]AngularJS 1.5 component styles aren't applied
Several times I noticed that styles added for AngularJS 1.5 components aren't really applied and now I encountered this again and can't google the reason why it happens so.有几次我注意到为 AngularJS 1.5 组件添加的样式并没有真正应用,现在我再次遇到了这个问题,并且无法通过谷歌搜索它发生的原因。 The situation: I've got view
home
and component bt-table
inside it.情况:我在里面有视图
home
和组件bt-table
。
Simplified template:简化模板:
<section id="home">
<bt-table data="hc.tableData" options="hc.tableOptions"></bt-table>
</section>
In styles (sass) for home
I write the following selector:在
home
样式(sass)中,我编写了以下选择器:
#home
bt-table
margin: 0 0 30px 0
Then I see it's not applied, go to devtools and see that styles are actually parsed by browser:然后我看到它没有应用,转到 devtools 并看到样式实际上是由浏览器解析的:
Also intresting: when I hover component in elements, I see this:同样有趣的是:当我将组件悬停在元素中时,我看到了:
Notice how element isn't highlighted with blue as normal even though it has non-zero size?请注意,即使元素的大小非零,它也不会像平常一样用蓝色突出显示?
So, why can it work so?那么,为什么它可以这样工作呢? Has it something to do with AngularJS template compilation process (it's my guess) or there are another reasons?
是否与 AngularJS 模板编译过程有关(这是我的猜测)还是有其他原因?
UPD: if I set border: 10px solid red
for element, that gets rendered: UPD:如果我为元素设置
border: 10px solid red
,则会呈现:
UPD: the markup inside bt-table looks like this: UPD: bt-table 中的标记如下所示:
<section id="table">
<div class="panel panel-default">
<div class="panel-heading">Table</div>
<table st-table="tc.data.data" class="table table-striped">
<!-- HEADERS, SORTING AND SEARCHBARS -->
<thead>
<tr>
<th ng-repeat="header in tc.data.headers" st-sort="{{header.sortsearch}}" ng-bind="header.title"></th>
</tr>
<tr ng-if="tc.options.search === 'every'">
<th ng-repeat="header in tc.data.headers">
<input st-search="{{header.sortsearch}}" placeholder="search for {{header.title.toLowerCase()}}" class="input-sm form-control" type="search"/>
</th>
</tr>
<tr ng-if="tc.options.search === 'all'">
<th>
<input st-search placeholder="search in all columns" class="input-sm form-control" type="search"/>
</th>
</tr>
</thead>
<!-- CONTENT -->
<tbody>
<tr ng-repeat="row in tc.data.data">
<td ng-repeat="column in row" ng-bind="column"></td>
</tr>
</tbody>
<!-- PAGINATION -->
<tfoot ng-if="tc.options.pagination">
<tr ng-if="tc.tdata.options.pagination.type === 'buttons'">
<td colspan="5" class="text-right">
<div st-pagination="" st-items-by-page="tc.tdata.options.pagination.itemsByPage" class="no-margin"></div>
</td>
</tr>
<tr ng-if="tc.options.pagination.type === 'input'">
<td colspan="5" class="text-right">
<div st-pagination="" st-items-by-page="tc.options.pagination.itemsByPage" st-template="components/l-table/custom-pagination.custom.html" class="no-margin"></div>
</td>
</tr>
</tfoot>
</table>
</div>
</section>
It's probably because you are targeting a custom element and chrome is setting it to display:inline
.这可能是因为您的目标是自定义元素,而 chrome 将其设置为
display:inline
。 Two options:两种选择:
Option 1 : Add a style of "block".选项1 :添加“块”样式。
bt-table{
display: block;
}
Option 2 use replace(which is what I would do).选项 2使用替换(这是我会做的)。 You would set
replace:true
on the directive and then targeting the first child of section which isn't a custom element and will display to block
:您可以在指令上设置
replace:true
,然后定位不是自定义元素并将显示为block
的第一个子节:
<section id="table">
Other suggestions pick something else besides id=table .其他建议选择除 id=table 之外的其他内容。
id
s are supposed to be unique on the page. id
应该在页面上是唯一的。 I'd recommend adding a class selector to target:我建议添加一个类选择器来定位:
eg例如
<section class="btn-table">
Then update your styles to:然后将您的样式更新为:
#home .bt-table{
margin: 0 0 30px 0
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.