What is the best way to cover a specific area of a webpage in a responsive layout with CSS?

When users interact with the page, multiple areas load asynchronously. Unlike hhgregg.com which masks the entire page, I want to mask only the specific region that is loading.

<div id="A">Loaded by Xhr</div>
<div id="B">Loaded by xhr based on actions with A</div>
<div id="C">Loaded by xhr based on action within B</div>

Since these regions are sized according to screen resolution, setting an absolute position for a loading gif won't work.

How can I use CSS to create a loading mask that covers just the div where the loading is happening? The loading mask itself is not the issue, it's figuring out how to target and fill only the desired div.

Answer №1

DEMO: http://jsfiddle.net/dwabU/1/

To create a masked effect on any specific DIV element, simply add the class masked to it.

CSS:

div.masked {
    position: relative;
}

div.masked:before {
    position:absolute;
    content: "MASKED CONTENT";
    display:block;
    width: 100%;
    height: 100%;
    background-color: rgba(70, 70, 70, 0.7);
    z-index:1;
    color: #ff0;
}

HTML:

<div id="A">Loaded by Xhr</div>
<div id="B" class="masked">Loaded by xhr based on actions with A</div>
<div id="C">Loaded by xhr based on action within B</div>

Answer №2

When creating your xhr script, remember to assign the loading div a class of loading. In your CSS file, you can style this class like so:

.loading{
background-image:url(loading.gif);
background-size:contain;
}

Answer №3

To ensure content is covered while AJAX is loading, apply a position:relative to each div that needs coverage. Utilize pseudo-elements for each div to create the covering effect.

For instance:
#B{position:relative;}

#B:before{content:""; position:absolute; top:0; left:0; width:100%; height:100%; background:black;display:none;}

Toggle the pseudo-element to display:block when AJAX is in progress, then hide it once the content is loaded.

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

Tips for creating pill progress bars that overlap each other

I am attempting to design a progress bar in bootstrap that displays projected and actual results, with a unique rounded "pill" shape on the right side. Below is the code snippet showcasing my progress: const data = { actual: 1155, projected: 1 ...

My body's padding-right is being altered by Bootstarp/CSS Popup

This is the padding for my body content. https://i.sstatic.net/LG7IE.png <div class="modal fade" id="exampleModal2" tabindex="-1" aria-labelledby="exampleModal2Label" aria-hidden="true" style="padd ...

My custom class is adding the Bootstraps class

Dealing with multiple tables of the same size can be a hassle when adding individual classes to each one. Is there a way to apply multiple Bootstrap classes to one class in the stylesheet? For example, using <table class='table table dark> curre ...

What is the best way to align a form in the center of a page both horizontally and vertically

Currently, this is the HTML code I am working with: <body> <form id="form_login"> <p> <input type="text" id="username" placeholder="username" /> </p> ...

Transform the look of your bootstrap 5 inputs by making them dark-themed

I have a feature in my app that allows users to switch between light and dark modes. Currently, I am using Bootstrap 5 form-control inputs and want to customize their background color based on the mode selected. Which CSS classes do I need to target in or ...

The CSS for selecting the input[type="submit"] element is not functioning as expected

I apologize but I am encountering an issue with my .css stylesheet that covers styles for my input type buttons as shown below. input[type="submit"] input[type="submit"]:hover input[type="submit"]:focus The first three selectors are functioning well, how ...

positioning of content on the left, right, and center

My task involves using CSS to adjust the positions of various elements on a webpage. Currently, the right position navigation bar and the liquid layout are working fine, but the positioning of the "content" and "right navigation bar" is not correct. I ai ...

Arrange two divs next to each other on the page: the div on the right can be scrolled through, while the div on the

I am attempting to create a layout similar to this https://i.sstatic.net/Y1FCp.png My goal is to: Have two main divs positioned side by side inside a wrapper div Ensure the wrapper expands to fill 100% of the browser size The left div (banner) should b ...

Creating a responsive grid layout in Bootstrap with varying row heights

Seeking assistance on incorporating a Bootstrap row with the col-lg-3 class. The challenge lies in accommodating articles of varying text lengths within a div with uneven heights. Present output can be viewed here, while desired output can be seen here. ...

CodenameOne's innovative solution allows for the seamless conversion of a theme.res file into CSS format with ease

Thanks to the cn1-css library, Cascading Stylesheet Support for Codename One is made possible. I'm curious about whether there is a way to automatically convert a theme file (theme.res) into CSS code. And, if so, how are the images from the theme fil ...

Feeling lost when it comes to forms and hitting that submit button?

Below is a sample form structure: <html> <head> <title>My Page</title> </head> <body> <form name="myform" action="http://www.abcdefg.com/my.cgi" method="POST"> <div align="center"> <br><br; <br& ...

The CSS media query isn't functioning properly on Safari browser

Currently, I am working on a project using React JS and CSS. In order to make it responsive, I have implemented media queries. However, I have encountered an issue where the media query is not functioning properly in Safari browsers on both phones and PC ...

How to Use Laravel to Create HTML Divs Without Images

While working with a text editor, we have the ability to incorporate various HTML tags such as images and videos. However, I am only interested in displaying text fields. When I use {{$loop->content}}, it displays: <p><strong>EXAMPLE</st ...

PNG file unable to display in Google Chrome

I created an image using paint.net and saved it as a .png file. However, when I try to display the image on my website, only the borders show up without any image content. Here is the code I used: HTML <a href="home.php"><img id="logo" src="../i ...

Arranging social media sharing icons on a website [Facebook, Twitter, Pinterest, and Google +]

Struggling with aligning the Facebook share button in my Shopify blog page template. It seems to be 5px lower than the other share buttons. Take a look at the issue https://i.sstatic.net/u0sFp.png The code for the Facebook share button is: <div style= ...

Ensuring that a nested div adjusts responsively within a static parent container

I am working on a project that involves HTML, CSS, and JS code. Here is the structure of my code: HTML: <div id="blockcart-wrapper"> <div class="blockcart cart-preview"> <div class="header"> <a rel="nofollow" href="#"> ...

What's causing my links to change to a golden hue?

After deciding to explore coding with Codecademy, I found myself facing an issue where three links that were meant to be blue ended up having one link in yellow. In addition to this, I couldn't figure out how to center align the links despite trying " ...

The span's presence causes the neighboring span to shift downwards

HTML <span class="symbol">$</span> <span class="value">400</span> This code snippet displays the symbols "$" and "400" at the same level in the document. However, if we introduce some styling using CSS: .symbol { font-size: 2e ...

What is the easiest way to eliminate horizontal lines in an HTML table?

I am struggling to remove the horizontal lines from my HTML table Although I have attempted using CSS properties like border-bottom and border-top with a value of 0, they did not make any difference. On the other hand, border-right and border-left are fun ...

Error: The selector "button" cannot be used in its current form as it is not pure. Pure selectors must include at least one local class or ID

<button onClick={() => resetBoard()}> Reset Board </button> While trying to import an external CSS file as a module, I encountered a problem. The CSS file looks like this... button { background-color: ...