Remove the opacity setting from a transparent box that covers the entire page

I find that real code tends to be more complex, but this snippet does a good job of highlighting the issue at hand.

In my setup, there's a background video playing (in this case, just as the background), and on top of that sits a transparent watch face in the shape of a square. The intent is for the viewer to see the background video through the dial. However, I've applied an rgba(0,0,0,0.2) filter to the background video to darken it. Within the watch's dial, I want the original video to show without this effect. I'm not sure if this can be achieved using CSS alone.

So, in this snippet, how can I ensure that the square displays solid black color without simply setting its color? In the actual code, this isn't an option since the square is meant to be transparent with a video passing through it.

.container{
  height: 100vh;
  width: 100vw;
  background-color: rgba(0,0,0,0.2);
  display: flex;
  justify-content: center;
  align-items: center;
}

/* square background should be black, so no opacity on it */
.square{
  width: 100px;
  height: 100px;
  border: 1px solid red;
}
<div class="container">
  <div class="square"></div>
</div>

Answer №1

It appears that I have grasped the concept of what you are seeking. A generous spread shadow applied to the box should achieve the desired effect.

.container {
  height: 100vh;
  width: 100vw;
  background-color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  background-position: center;
  background-size: cover;
  background-image: url('https://images.unsplash.com/photo-1454496522488-7a8e488e8606?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8bW91bnRhaW58ZW58MHx8MHx8fDA%3D&auto=format&fit=crop&w=900&q=60');

}

.square {
  width: 100px;
  height: 100px;
  box-shadow: 0 0 0 50vw rgba(0, 0, 0, 0.8);
}
<div class="container">
  <div class="square"></div>
</div>

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

Ensure the clarity tabs labels have the padding-left CSS property added

In my project, there are 2 clarity tabs (you can view the StackBlitz reference here). I want to apply the padding-left property specifically to Tab1 (the tab label itself, not the content) in order to create some space around it. Through Chrome Dev Tools, ...

Assign the two values to variables in the CSS script

My challenge lies in passing two values to the CSS within the <style> tags. The values are: (background-color: --placeholder; color: --placeholdtext;). I am able to pass either one of the values successfully, but not both at the same time. When I cop ...

Is there a way to extract all the aria-label attributes from elements that share a common class?

I am currently working on a program that tallies the number of reactions from Facebook posts, with each reaction stored in an aria label containing detailed information. I am encountering difficulty retrieving the values of these unique aria labels due to ...

Trigger a database update upon clicking the submit button

Greetings! I am a newcomer to the world of PHP and have scoured Stack Overflow for solutions to no avail. My query revolves around updating a database when a submit button is clicked. Below, you will find the code associated with this submit button. <? ...

Is it possible to trigger a JavaScript function and an AJAX command with just one button click?

I'm looking to achieve a specific functionality using one button within a form. The requirements are as follows: 1) When the button is clicked, it should trigger a JavaScript function that performs animations such as fadeout and fadein. 2) Following ...

"Utilizing nested div tags for precise positioning within a parent div tag

For days, I have been attempting to align 4 div tags (accommodation site widgets) within another div tag so that they are displayed in a single horizontal line side by side. Despite using CSS properties such as "float" and "display", only 2 out of the 4 di ...

Adjusting the alignment of Bootstrap navbar items upon clicking the toggle button

When I click the toggle button on a small screen, my navbar items appear below the search bar instead of aligning with the home and about elements. Below is an image depicting this issue: https://i.stack.imgur.com/4rabW.png Below is the HTML code structu ...

Ways to choose a designated element without relying on ids or classes

I am looking to create an on-click function for each button, so I require a method to select each one individually without relying on IDs <div class="col"> <div> <b>Name:</b> <span ...

Transfer information from the client to the server using AJAX and PHP by

When attempting to post a JavaScript variable called posY to a PHP file, an error occurred with the message: Notice: Undefined index: data in C:\xampp\htdocs\Heads_in_the_clouds\submitposY.php The posY variable is defined in the JavaSc ...

Having issues with the alignment on Bootstrap 4, any suggestions on how to fix it?

I'm struggling with the layout of a web page using Bootstrap 4, and for some reason, I can't figure out why it's not displaying correctly. I've been staring at my code for about 15 minutes now, but I just can't seem to identify the ...

Attempting to design a customized tooltip for an SVG element embedded within the HTML code

Recently, I've delved into Js with the goal of creating an interactive pronunciation guide using inline svg. If you're curious to see what I've done so far, check it out here. My current focus is on incorporating basic styled tooltips that ...

Creating a List with Sublists that are displayed when hovering over the parent List is a key element of effective design

Hovering over 'View Rows' should open up both New Records and Old Records <div> <li>Add Rows</li> <li>DeleteRows</li> <li>View Rows <ul> <li>View New Records</li ...

Creating a sort button in HTML that can efficiently sort various divs within a table is a useful tool for enhancing user experience

My HTML table is populated with various <td> elements. How can I arrange these divs based on IMDb rating, TomatoMeter, etc... [ CSS code is not provided below ] <table> <tr class="row"> <td class="column"> <br> ...

Guide to placing an image in a designated position

I am looking to achieve the following scenario: Whenever a user uploads an image, it should appear in one of the smaller boxes on the right. Subsequent image uploads by clicking on the big box should populate the other small boxes on the right. Please refe ...

Removing a function when changing screen size, specifically for responsive menus

$(document).ready(function () { // retrieve the width of the screen var screenWidth = 0; $(window).resize(function () { screenWidth = $(document).width(); // if the document's width is less than 768 pixels ...

Error encountered when trying to load Ajax script

As a beginner in the learning process, my code may appear messy. I am currently wrapping up my second project, which is a photo viewer. On the main page, there is a navigation system that loads different sections of the website using ajax. Since this proje ...

Map on leaflet not showing up

I followed the tutorial at http://leafletjs.com/examples/quick-start/ as instructed. After downloading the css and js files to my local directory, I expected to see a map but all I get is a gray background. Can anyone advise me on what might be missing? T ...

The CSS media queries are failing to adjust the properties from 1024 to 768 as expected

Currently, I am working on implementing media queries to customize the color scheme for different screen sizes - particularly in 1024 view and 768 view. However, one issue that I encountered is that the properties defined for the 1024 view are being inheri ...

Is it necessary to add a line break after a span element generated by react, next, or bootstrap

There is a strange issue plaguing my code - I'm enclosing some text in a span tag and it's causing an unexpected line break. It's unclear whether React.js, Next.js, or Bootstrap is the culprit, but I can't seem to get rid of the pesky l ...

What is the method for incorporating this effect into the final sentence of a text?

I am trying to create a unique design effect by applying a custom border to only the last line of text. You can see an example here. In this scenario, the target text is "2000 years old." (with that specific length) and not the entire width of the parent ...