Display the content within a div as a background image

I am attempting to design a div that initially displays the text loading..., and then can be covered by new elements as they are loaded into it. Below is the code snippet I am working with:

<div class="results" style="position:relative;" *ngIf="showResults">
    <!-- Show 'loading...' before the results load, which will then overlap this text -->
    <div stlye="position: absolute; z-index: -1;">Loading ...</div>
    <!-- Angular2 loop to asynchronously load results -->
    <div *ngFor="let loc of searchLocations | async" (click)="selectLocation(loc)" class="search-result">
        {{ loc.name }}, {{ loc.adminName1 }}, {{ loc.countryCode }}
    </div>
</div>

However, when I execute this code, the result is similar to what is shown in the following image:

https://i.sstatic.net/5U2J0.png

The issue is that my 'loading...' text has its own boundary, instead of allowing the subsequent elements to overlap it. How can I achieve the desired effect?

Answer №1

To simplify the process, consider creating a boolean variable to handle the loader display.

export class YourComponent(){
   showLoader:boolean = true;
   constructor(){
       // Depending on your GET request implementation
       // Set isLoading to false once data is fetched
       // Example: after fetching data and assigning it to searchLocations
          showLoader = false;
       } 
   }
}

In your HTML template, utilize *ngIf directive for conditional rendering:

<div style="position: absolute; z-index: -1;" 
      *ngIf="showLoader">Loading ...</div>

You have the option of turning the loader into a reusable component or linking it to showResults variable by placing the loading div outside the showResults div with *ngIf="!showResults". This might require some styling adjustments.

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

css customized vertical scrollbar for a static division panel

I have the following HTML content and I need a fixed sidebar with 100% height. The vertical scrollbar should appear when content is added in mainContent or Content. <div class="mainContainer"> <h2>Title</h2> <div class="Content"&g ...

iOS Font Display Issue in Ionic 2

I am currently in the process of developing an app using Ionic 2 and I want to incorporate a custom font called Quicksand. Here is how my folder structure looks: src | |-app | | | -app | | | | | -app.scss | | | -pages | | | -assets | ...

Stop jQuery timeout when mouse hovers over a div

I'm currently dealing with a class: <ul class="topStatsWrapper"> <li><a href="">link</a></li> <li><a href="">link</a></li> <li><a href="">link</a></li> </ul& ...

Column that adjusts to different screen sizes

In the realm of responsive web design, what methods are suggested to achieve the specified CSS display? My main requirement is to have a maximum of three columns. The content should be divided evenly among these three columns. I prefer using SCSS and wel ...

Improving efficiency of basic image carousel in Angular 8

In my Angular 8 app, I am developing a basic carousel without relying on external libraries like jQuery or NgB. Instead, I opted to use pure JS for the task. However, the code seems quite cumbersome and I believe there must be a more efficient way to achie ...

Is the checkbox automatically selected if a property is specified?

I am completely frustrated by this problem. I am struggling to find a way to toggle a checkbox using JavaScript. Here is the HTML code snippet in question: <div class="form-group"> <label class="col-sm-3 control-label"></label> < ...

Strings of text randomly popping up above the page's content while utilizing the Repeater control

Currently, I am encountering an issue with page rendering while working on my project in C# .NET 4.5 and using Visual Studio 2015 as my primary development environment. The strange thing is that when I debug the site locally within Visual Studio, all the p ...

Why does the "margin" CSS style fail to function properly in FlowPanel within GWT?

I'm currently working with Gwt and have encountered a problem with styling buttons. Let's take a look at the following code snippet: .marginRight{ margin-right: 10px; } FlowPanel myFP=new FlowPanel(); Button myButton=new Button("Button"); Butt ...

Is there a way to prevent the removal of CSS files from a module when deploying a Next JS API to Vercel?

Is there a way to access a css file from a node_modules package in order to generate swagger documentation within an endpoint using the Next API? I have noticed that tree shaking is removing the css files from the swagger-ui-dist package. How can this be ...

What is the best way to apply a top padding to a background image using CSS?

I attempted to adjust the top padding using various pixel values in the style, but the image padding relative to the webpage remained unchanged. For example: padding-top: 5px; Here is part of my code snippet: <div class="row pb-5 mt-4" style ...

Incapable of smoothly scrolling through individual div tags

I am facing an issue with my ajax page (search.js) attached to my main page that runs a setInterval every 2 seconds. On the main page, I have a div tag (class="view") that can slide down and interrupt the interval. Everything is working fine except when I ...

What is the proper way to utilize a variable within the translate3d function?

Currently, I am developing my portfolio and working on a function in JavaScript called translate3d(0,10px,0). My question is, how can I use a variable instead of hardcoding the value 10px? I attempted to use translate3d(0,a,0) where 'a' is a vari ...

Show HTML content retrieved from a JSON response

I have developed a basic system that retrieves data from my JSON file instead of relying on a database. The functionality works well, however, I am encountering a problem with the html tags being displayed as plain text. It's important to mention that ...

Moving elements using CSS

Hi, I've been facing this issue with my web development since the start. Whenever I zoom in, the container also moves along. Is there any way to fix this problem? .darkslidecont{ width: 200px; height: 50px; position: relative; bac ...

Ensure that the footer is always positioned at the bottom of the page according

I've been struggling to get my footer to stay at the bottom of the page based on content. I've tried several CSS techniques and strategies, but I'm still encountering one issue. footer { width: 100%; padding: 25px 0 25px; backgr ...

What is the best method to vertically center a container in bootstrap 4 at a specified height?

I'm trying to center a container in Bootstrap 4. I have an element with a width of 300px. .guide-background{ background: url("https://www.webascender.com/wp-content/uploads/executive-guide-1.jpg"); background-repeat: no-repeat; backgrou ...

Creating a secondary menu within the existing menu using Bootstrap 3

I am trying to create a dropdown submenu using Bootstrap 3. While there are many resources discussing this topic, one in particular that has been helpful so far is this post: Bootstrap 3 dropdown sub menu missing However, the solutions provided in that t ...

Is there a way to make the delete button remove just one item from the local storage?

Is there a way to make the delete button on each item in a list remove only that specific item without deleting the others and also remove it from local storage? I have been trying to figure this out but haven't had any success so far. <div class ...

Creating a Drop-Down Button Using HTML, CSS, and JavaScript

I am currently working with the following code: <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=PT+Sans ...

Having difficulty sending a value with %45 to a REST API

Currently, I'm encountering an issue within my ASP.NET MVC 5 application. The problem arises when I send the following JSON data to a third-party API, which includes a password field: "{\"operation\":{\"Details\":{\"RESOURCE ...