Adjusting the transparency of the background without impacting the text itself

I've been struggling to create a loading screen with no luck.

The animation itself looks fine, but the background is causing issues. Every time I try to adjust the opacity, it affects the text as well.

@import url('https://fonts.googleapis.com/css?family=PT+Sans+Narrow');
.yes
{
    background:black ;
}
.loading {
    font-family: PT Sans Narrow;
    font-weight: bold;
    font-size: 30px;
    color:black;
    top: 45%;
    left: 45%;
    position: absolute;
    color:white !important;
}
.loading:after {
    overflow: hidden;
    display: inline-block;
    vertical-align: bottom;
    -webkit-animation: ellipsis steps(5,end) 1000ms infinite;      
    animation: ellipsis steps(5,end) 1000ms infinite;
    content: "....";
    width: 0px;
}
@keyframes ellipsis {
    to {
        width: 0.9em;    
    }
}
@-webkit-keyframes ellipsis {
    to {
        width: 1em;    
    }
}
<body class="yes">
<p class=" loading ">Loading</p>
</body>

Answer №1

For the background color, consider using RGBA. The alpha channel, represented by the fourth parameter in the rgba function, determines the opacity of the color. An alpha value ranging from 0 (fully transparent) to 1 (opaque) can be set.

background: rgba(0, 0, 0, 0.5);

This change in background color does not affect the appearance of any child elements within the specified element.

@import url('https://fonts.googleapis.com/css?family=PT+Sans+Narrow');

body {
  margin: 0;
  background: url(http://lorempixel.com/1200/600);
  background-size: cover;
}

.yes {
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
}

.loading {
  font-family: PT Sans Narrow;
  font-weight: bold;
  font-size: 30px;
  color: black;
  top: 45%;
  left: 45%;
  position: absolute;
  color: white !important;
}

.loading:after {
  overflow: hidden;
  display: inline-block;
  vertical-align: bottom;
  -webkit-animation: ellipsis steps(5, end) 1000ms infinite;
  animation: ellipsis steps(5, end) 1000ms infinite;
  content: "....";
  /* ascii code for the ellipsis character */
  width: 0px;
}

@keyframes ellipsis {
  to {
    width: 0.9em;
  }
}

@-webkit-keyframes ellipsis {
  to {
    width: 1em;
  }
}
<div class="yes">
  <p class=" loading ">Loading</p>
</div>

Answer №2

Attempting to adjust the transparency of the background color? Simply utilize RGBA, with the last parameter indicating the opacity level.

background-color: rgba(0, 0, 0, 0.7);

Answer №3

Instead of using background:black in your CSS class, try incorporating this property:

.yes{background: rgba(0,0,0,0.6); }

It is recommended to use rgba for filling areas with transparent color. The first three values stand for the color in RGB format, while the fourth value determines transparency on a scale from 0 to 1 (0 being fully transparent and 1 being fully opaque). While opacity is a related property, it affects all descendant elements' transparency without exception, unlike rgba.

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

Creating Visuals with CSS Gradients: A Tutorial on Generating Images and SVG Files

I currently have a CSS gradient applied and I am interested in creating an image or SVG file from it. However, I am unsure of how to accomplish this task. Any advice would be greatly appreciated. background: -webkit-linear-gradient(bottom, rgb(211, 208, ...

Center the background image at the halfway mark on the screen

Can someone help me figure out how to position an image so that it appears exactly at the halfway point of the screen? I've researched different ways to position images within a div, but I'm struggling with positioning it on the entire screen. ...

Ways to animate a main element independently of its counterpart's animation

I want to create an animation for a parent element without affecting the child's animation. My HTML & CSS structure is set up as follows: .parent{ background-image: url('https://pm1.narvii.com/6195/421ddbf8c9a2fb1715ef833f869164dc1be ...

Switching the file format from HTML to .ASP resulted in the loss of the website's design elements and images

After initially creating an HTML file, I decided to rename it with a .asp extension for uploading online. To do this, I copied the original HTML file and moved it into a folder containing .asp files. However, after replacing the existing file, my website l ...

Discovering the proper method to reach the parent element in jQuery while within the click event

How can I use jQuery to access the parent element within a click event? $(document).ready(function () { $(".lv1 li").click(function (event) { this.parentElement.parentElement.textContent = this.textContent; $.ajax({ type: 'post&apo ...

What are the distinct components used in CSS for :target?

I've encountered an issue with nesting :target pseudoclasses. Currently, I have a section containing an anchor tag. Right now, everything is functioning as intended; when I click on the anchor linking to #Current, it expands the area and displays the ...

Retrieve the bounding rectangle of a div that has the CSS style `display: contents` using the getBoundingClientRect

My objective is to apply styling and obtain the bounding box of an entire "row" within a CSS grid, including features like highlighting when hovering over it. To achieve the styling aspect, I make use of the display: contents property, so that the styles ...

Is there a way to modify or update the CSS classes and overall styling in .gsp files within the Grails framework?

What is the best way to dynamically update a DOM element's class and styling in response to specific conditions or events occurring in a .gsp file? ...

What is the best way to structure the layout: Subdomains or External CSS for Web and Mobile Web?

I'm currently working on designing an application that needs to be compatible with both web and mobile web browsers. Due to the differences in screen sizes, I understand that I will need to create different layouts and views to ensure optimal user exp ...

Having trouble getting rid of the border-bottom?

I have been attempting to customize the appearance of the React Material UI tabs in order to achieve a design similar to this: https://i.stack.imgur.com/tBS1K.png My efforts involved setting box-shadow for the selected tab and removing the bottom border. ...

Designing a dynamic button that expands on hover to catch the eye

My instructor has provided us with this code snippet: <a class="btn btn-tertiary" href="#"> <span class="circle"> <i class="arrow-right"> </i> </span>Create profile </a> .btn.bt ...

The html input box's ability to handle overflow situations

Currently, I am working on creating a form that allows users to update data. <dl> <dt>Medical Needs:</dt> <dd class="med_needs" style="height:60px;overflow:auto"> <input type = "text" id="med_needs"name ="med_nee ...

Adjust the size of the div menu according to the window's dimensions

Is there a way to make a menu that will resize both the width and height of the window? I've managed to resize the width using %, but for some reason, the height isn't cooperating. I've experimented with max-width/height settings and tried ...

Make the text within the CSS style of ".well" wrap around the width

I am looking to style the width of a .well class to be in proportion with the text inside a simple textbox that it contains. What is the best approach to achieve this sizing using CSS? ...

Resolving Issues with Page Feature Images on Your WordPress Site

Currently enrolled in a web development course, I collaborated with my instructor to create a custom website. However, I am facing an issue where the header image appears shorter on the Resources page () and Contact page () compared to the Blog page (). De ...

The hamburger icon seems to be frozen and unresponsive

I'm struggling to get my hamburger icon to reveal the navigation bar when clicked. The icon itself functions properly and adapts to different screen sizes, but the overlay remains stationary. Check out my code on JSFiddle! <html> <head> ...

Instructions for developing an HTML element slider using mouse dragging

I've come across plenty of slider plugins that either only allow clicking to view the next image, or if they do support mouse drag or touch capabilities, they are limited to images. Does anyone know of a plugin or method to create a mouse drag slider ...

Issue with MUI Grid item not functioning properly when using overflowY: "auto"

I am encountering an issue while using MUI with React. I have a <Paper> element wrapping a <Grid> with 3 children elements. The problem arises when I set the overflowY property of the bottom grid item to "auto" - instead of showing the scroll b ...

Difficulty with aligning textfield controls to the right

I'm currently working on adding StaticTextField controls to a page. We are using ExtJS, but we incorporate VB.NET methods for implementing ExtJS so manual coding isn't necessary. So far, I attempted to align the text to the right by using this c ...

Innovative HTML5 Video Canvas Shapes

I'm currently working on creating a circular frame or canvas for live HTML5 Video. While I am able to round the corners using keyframes radius property, it results in an oval shape rather than a circle. My preference would be to utilize a div object ...