Setting the transparency of a page using the `Div::after` method

I've encountered an issue with my CSS sheet that is causing one of my webpages to match the opacity of the background image, while the others do not exhibit this behavior. I specifically want only the background to have the opacity and not affect the rest of the content. After experimenting with the code, it seems like the problem only occurs on this particular page because it contains a table, whereas the other pages either have a form or no special elements. Should I provide some snippets of the HTML for further clarity? The problematic CSS code snippet looks like this:

 div::after {
  min-height: 100%;
  min-width: 1024px;
  pointer-events: none;
  width: 100%;
  height: auto;
  top: 0;
  left: 0;
  content: "";
  display: block;
  position: fixed;
  background: url(brain.jpg) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  opacity: 0.1;
}

In addition, here is some added HTML code:

<html>
<head>
    <meta charset="utf-8" />
    <script>
        function view() {
            // JavaScript function for displaying content
        }
    </script>
    <link href="general.css" rel="stylesheet" />
</head>
<body>
    <!-- Page layout and structure -->
</body>
</html>

The current appearance of the affected webpage displays a similar opacity as the background throughout the content, which is undesired. I aim to achieve a layout similar to another page where only the background has the applied opacity. Refer to the provided images for comparison:https://i.sstatic.net/CXhlT.pnghttps://i.sstatic.net/ea7zg.png

Answer №1

Hey @jackie, just a little heads up - this solution won't actually make everything transparent. What it does is position the image on top of your page content, giving the illusion of opacity. To achieve this effect, you'll need to adjust the z-index of the ::after pseudo-element to -1.

div::after {
  min-height: 100%;
  min-width: 1024px;
  pointer-events: none;
  width: 100%;
  height: auto;
  top: 0;
  left: 0;
  content: "";
  display: block;
  position: fixed;
  background: url(brain.jpg) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  opacity: 0.1;
  z-index: -1;
}

As mentioned before, it might be more efficient to target a specific element with a class rather than applying ::after directly to every div element. Just some food for thought!

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

Exploring the power of Bootstrap 5 for vertical alignment

I am currently utilizing the flexbox grid from Bootstrap 5 to create a mobile-first Angular web application that is responsive. For the home screen of my app, I want to incorporate these 3 elements : The title of the app displayed at the top A series of ...

Having difficulty implementing DragControls

My experience with three.js is at a beginner level, and I recently attempted to incorporate a feature allowing the dragging of a 3D model. During this process, I encountered DragControl but faced difficulty implementing it in my code. Upon using new DragCo ...

Tips on utilizing jQuery to trim and manipulate the current URL

Suppose the current URL I am working with is: https://example.com/test?id=W2FiY11beHl6XVsxMjNd . The data following ?id is [abc][xyz][123] and it is base64 encoded. My objective is to manipulate the current URL in such a way that the content displayed on ...

I'm having trouble with my bootstrap dropdown and I've exhausted all of my options trying to fix it based on my current understanding

My dropdown menu is not working despite adding all necessary Bootstrap CDN and files along with the jQuery script. Even with the table being handled by JavaScript, the button does not respond when clicked repeatedly. I suspect the issue lies within the han ...

The margin-top property in CSS is not functioning as intended for a specific pixel value when applied to

I'm having trouble with positioning an icon using margin-top: -35px; under #menu. When I click on the icon, the side navigation bar doesn't work properly. However, if I adjust it to -15px, the side navigation bar displays correctly. Can someone h ...

Stretching Images on Circular Images - Utilizing Bootstrap and SCSS styling

Can anyone assist me with this problem? I am currently utilizing bootstrap cards to create a section on my website. However, I am encountering an issue with the circular images of the cards. I want to prevent my images from getting stretched when placed i ...

The find functionality in Angular and Firebase seems to be malfunctioning

enter image description here Whenever I try to find the ID and data set is not set on these fields, I encounter an error in my console. The following code snippet displays the find expense code: import { Component } from '@angular/core'; import ...

The input box within the form is insufficiently sized

My task is to generate textareas with custom parameters like "cols" and "rows" and display them in forms. However, these parameters seem not to be functioning as expected. Whether I set cols=1000 or cols=1, there is no difference in the output. After revie ...

How can you ensure a div stays at the top or bottom of a page based on the user's scrolling behavior?

Hello there! While I know there have been many questions regarding sticking a div to the top or bottom while scrolling, my particular issue is a bit more specific. My dilemma is that I am looking for the div to stick either to the top or the bottom based ...

Is it possible to establish a delay for requestAnimationFrame()?

My webpage has a very long layout with text in one column and a floating element in another. I want the floating element to follow the scroll of the window and return to its original offset once scrolling stops. The current code I have is: var ticking = ...

Looking for assistance with implementing a jQuery function for an onClick event on

I've been diving into learning jquery and managed to create a basic checkbox feature with a function that allows you to set all options as read-only by checking the "None of the above" button. <html> <body> <form id="diagnos ...

Struggling with setting margins effectively in Bootstrap for the desired layout

I am attempting to create two columns with space between them, but whenever I try to add a margin-right, one of the columns goes down. Can someone please assist me? <div class=row> <div class="boxi col-6"> Content here ...

The conditional ng-class styling will be applied to each and every div on the page

For a patient, I have a modal displaying a list of card numbers. If the card is set as the default card, it should have a grey background, based on a true value for the object. <td ng-repeat="obj in paymentAndShipping"> <div ng-click= ...

Customizing a Google chart legend to show on hover event

Utilizing the Google Chart API, I have created a line chart to display my data. To customize the legend, I initially set the chart's original legend to none and then designed my own legend according to my preferences. While everything is functioning ...

Can one determine whether an SCSS element is devoid of content?

Can SCSS be used to determine if an element is empty? For instance, I'm interested in assigning a variable based on whether the class has content or not. <div class="defaultClass"> <!-- This div is empty --> </div> Is there a w ...

Turning multiple .html files into a single csv using beautifulsoup

I am dealing with a situation where I have 13,000 html files stored in a folder and my goal is to consolidate all the data into a single csv file. Although I believe I have made progress in extracting the data, I am encountering challenges when it comes t ...

Slider Troubles - Strange glitch when reaching final slide

Currently, I am in the process of developing a basic slider for a website. Although it is still a work in progress and both the script and styling are unfinished, I have encountered an issue. After clicking on the next button, I am able to cycle through al ...

Using JavaScript to execute a PHP function for updating or inserting data into an SQL database

I seem to be facing some minor issues at the moment. I have this JavaScript function that updates the stream of the VLC web plugin. However, what I am really trying to do is incorporate a way to input data into my database to keep track of how many viewers ...

Responsive tables in Bootstrap 4 that are nested

I am currently utilizing Bootstrap 4. I have a complex table structure where I want only the second column and onward to be scrollable. The challenge is making this specific part of the table responsive while keeping the rest static. I attempted to nest a ...

How to customize Django form without using bootstrap styling

Hello, I am new to Django and I have been searching for tutorials on how to style Django forms without using Bootstrap. Is it possible to style Django forms using pure CSS without Bootstrap? If so, could you please provide some examples? I prefer not to u ...