我有一个简单的 UI Bootstrap 警报,用于显示错误消息等。 我将它(默认情况下)隐藏在我页面顶部标题的正下方。 我可以使用范围变量更改颜色和文本,并使用 ng-hide 隐藏它。这是警报 html:
<alert type={{alertType}} close="hideAlert = true"
ng-hide="hideAlert" class="ng-hide">{{alertText}}</alert>
问题在于,当页面加载且警报被隐藏时,隐藏的警报会额外占用 20 像素左右的空间。当我检查元素时,似乎“x”关闭按钮占用了 21px 的空间,并且没有像警报那样缩小。这是元素控制台中显示的内容,
<button ng-show="closeable" type="button" class="close" ng-click="close($event)">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
此外,警报的文本元素做同样的事情,除了 20px 的空间 - 虽然这个空间包含在上面的 21px 中。元素控制台显示:
<div ng-transclude="">
<span class="ng-binding ng-scope">Default Alert!</span>
</div>
警报和 alert.ng-hide 的 CSS 如下所示:
.alert {
-moz-transition: 0.5s linear all;
-o-transition: 0.5s linear all;
-webkit-transition: 0.5s linear all;
transition: 0.5s linear all;
display: block !important;
max-height:50px;
opacity: 1;
}
.alert.ng-hide {
display: block !important;
max-height:0px;
opacity: 0;
padding-top: 0;
padding-bottom: 0;
margin-top: 0;
margin-bottom: 0;
}
知道为什么这些警报组件在隐藏时没有缩小吗?
最佳答案
我假设问题出在您的 CSS 行 display: block !important;
当 hideAlert
为真时,UI Bootstrap 应用 display:none;
到完全隐藏它的警报,但这正在被 display:block !important
覆盖。
我也不确定为什么您需要为 alert
元素中的类属性提供 ng-hide
值。
我也同意 ibrahimbayer 的观点,即使用 ng-if 可以解决问题。
关于javascript - 使用 AngularJS ng-hide 的 UI Bootstrap Alert 占用额外空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32594255/