AngularJS ng-hide in UI Bootstrap Alert causing unnecessary space occupation

Utilizing a simple UI Bootstrap alert to display error messages and more, I keep it hidden below a header at the top of my page by default. By using scope variables, I can customize the color and text and utilize ng-hide for hiding. Here's the alert HTML snippet:

<alert type={{alertType}} close="hideAlert = true"
    ng-hide="hideAlert" class="ng-hide">{{alertText}}</alert>

An issue arises when the page loads as there seems to be an extra 20px of space occupied by the hidden alert. Upon inspecting the elements, the 'x' close button consumes 21px of space and remains unaffected by the alert shrinking. The console displays this:

<button ng-show="closeable" type="button" class="close" ng-click="close($event)">
    <span aria-hidden="true">×</span>
    <span class="sr-only">Close</span>
</button>

Similarly, the text element within the alert encounters a similar issue, taking up 20px of space, nested inside the 21px mentioned earlier. This is evident in the element console:

<div ng-transclude="">
    <span class="ng-binding ng-scope">Default Alert!</span>
</div>

The CSS for both the alert and the hidden alert (alert.ng-hide) appears like this:

.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;
}

Any insights into why these alert components do not shrink when hidden?

Answer №1

The issue might be arising from the CSS line display: block !important;. When the variable hideAlert is true, UI Bootstrap sets the alert to display:none;, but this style is being overridden by display:block !important.

It seems unnecessary to manually set the ng-hide value in the class attribute of the alert element.

I concur with ibrahimbayer that using ng-if could be a simpler solution to this problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Include the content of a nested directive within the outer directive

Looking to implement a custom AngularJS directive called outer-directive that will wrap content (such as HTML or other directives) and dynamically create a small navigation on the left side. I'm having trouble getting this example to work. The conten ...

JavaScript click or text-to-speech

Currently, I am working on a web application that is designed to automatically read text. Below is the code snippet that I am using: function hablalo() { var palabra = new SpeechSynthesisUtterance('Casilla 6 turno E18'); palab ...

The Function(JS) is specifically designed to only function within the topmost div or quote

Currently, I am facing an issue with a function I have implemented. This function adds a blur effect to words in a Blockquote when the page is loaded. However, I need this function to work for all Blockquotes and different divs on the page, not just the to ...

Is there a way to eliminate shadows from a View/Image that is absolutely positioned

I recently added a materialistic "Add" button to my Android-primary React Native app. Despite using the elevation style property for shadows on other elements, it seems to stop working when applied to an absolutely positioned element. I understand that thi ...

Two boxes each taking up half of the width, with content placed inside a container

How can I achieve the appearance seen in this image? https://i.sstatic.net/2oZW8.png The layout consists of four columns using regular Bootstrap code. The first two columns should have a white background within a .container, while the other two columns s ...

`to shift the background image`

Seeking assistance with CSS as I am struggling to get it right. I have a div containing other elements: <div class="place_section" style="height:375px;" data-session="3" data-client="2"> <div class="row">1</div> <div id="3" cl ...

Guide: Communicating with child component functions from parent component in React/Typescript

I am facing an issue while trying to utilize the child component function "changeName" in a parent component. The error message I receive is: Property 'superheroElement' does not exist on type 'App'. How can I resolve this issue effecti ...

Use jQuery to select all div elements within another div and then verify each one's class

Currently, I am implementing a chat system where I display messages using jQuery, JSON, and PHP. The issue I am facing is that I need to iterate through each div within the "#chatMessages" container, which houses the messages, and verify its class existenc ...

Ways to transmit information among Vue components

I am trying to figure out how to pass data from the Module variable in CoreMods.vue to ExternalWebpage.vue using Vuex. I want the CoreModule state to be watched for changes in the external webpage. This is my store.js setup: import Vue from 'vue ...

When the value is blank, do not include the class attribute when appending

http://jsbin.com/guvixara/1/edit I have a situation where I am dynamically inserting a button... $(".confirm-add-button").on("click", function() { var $ctrl = $('<button/>').attr({ class: $('.newbtnclassname').val()}).html($(& ...

Is there a way to bypass media queries in a CSS file?

I'm working on a web project that includes a CSS file with media queries. However, for one specific page, I do not want to apply the media queries from this CSS file. How can I exclude them just for that particular page? ...

Utilize ASP to limit the application of a CSS file exclusively to the child page

My website consists of a master page and several child pages. I have created specific CSS classes for styling. However, I only want certain child pages to utilize these styles while the master page should always use them. How can I limit the access to th ...

Achieving a cumulative running balance using Vue js for nested arrays

I am looking to calculate the running balance by subtracting AmountApplied from Amort. Here is the desired output: Line Amort Total Payment Running Balance 1 30250 10000 20250.00 30250 20250 0.00 ...

Implementing ui-sref-active for intricate routing states

I have implemented the menu link using AngularJS and UI-Router. <li ui-sref-active="active"> <a ui-sref="dashboard" title="Dashboard"><i class="fa fa-lg fa-fw fa-home"></i> <span class="menu-item-parent">Dashboard</spa ...

Ways to monitor automatic data alterations within a Vue JS component

I have a method that updates data within the component itself, for example: Vue.component('component', { template: '#component', data: function () { return { dataToBeWatched: '' } }, methods: { chang ...

Execute a PHP SQL query when a link is clicked

To trigger a SQL query when a link is clicked, I have implemented the following code: mainpage.php: function deleteImage1() { $.post("delete_image.php", { num:1, id:<?php echo $id; ?> }, function(data,status){ alert("Data: " + data + "\n ...

Are there any reliable sources for a complete list of browser CSS properties?

Is there a way to easily access a comprehensive list of CSS properties supported by specific browsers, particularly IE8? Any suggestions on where I can find this information? ...

When $(.class) displays result, Javascript ceases execution

In the code snippet below, I am trying to load a group of products from a category when the user clicks on the .expandproducts button: $('.expandproducts').click(function(){ id = $(this).attr("data-id"); urlajax = document.location.origi ...

Attempt to resend requests that exceed the time limit by utilizing the angular $resource and implementing the retry

Is it possible to retry a failed request within the failure callback without using an interceptor? The request failed due to a timeout or another reason. $resource(url, {}, {get: {method: "GET"}}).get() .$promise.then(function (r ...

Save temporary data from a fluid position within the DOM into a JavaScript variable

Currently, I am constructing a website as part of a school project, so the design is relatively basic. Any incorrect usage of terms should be forgiven or rectified if necessary. In my project, there are several identical div elements, all sharing a common ...