gpt4 book ai didi

html - 如何将 ng-style 与 div :after? 一起使用

转载 作者:太空宇宙 更新时间:2023-11-04 01:05:48 25 4
gpt4 key购买 nike

我正在使用 Angular 1.x。

这是 code example在 jsfiddle 上。

如果 ctrl.shouldShowDiv2 = false 我不想显示 div2 否则 (ctrl.shouldShowDiv2 = true) 我想激活 框::之后。有没有办法让它与 ng-style 或任何其他指令一起工作?

This answer看起来与我想要的相似,但我无法理解。

谢谢。

最佳答案

您可以做的是创建一个单独的类,您可以在该类上使用 ::after 选择器。然后使用 ctrl.shouldShowDiv2 切换该类。这是一个例子:

angular.module('app', []);
.box {
height: 150px;
width: 200px;
overflow: hidden;
position: relative;
background: tomato;
}

.box-xtra::after {
content: "div2";
width: 100px;
height: 20px;
position: absolute;
top: 10px;
left: -30px;
transform: rotate(-45deg);
background-color: white;
text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js"></script>
<div ng-app="app">
<div style="margin-bottom: 10px;">
<label>Show div2 <input type="checkbox" ng-model="ctrl.shouldShowDiv2" /></label>
</div>
<div class="box" ng-class="{'box-xtra': ctrl.shouldShowDiv2}"></div>
</div>

关于html - 如何将 ng-style 与 div :after? 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52263694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com