I encountered a limitation in utilizing opacity with my background-image

I have been struggling to apply opacity to my background image while still being able to see and write text on it. I have tried various methods but either the text is visible without the ability to write on it, or only half the screen is covered with the background image. I am hoping to find a solution here.

* { margin: 0; padding: 0; }

/* Centering */
body
{
    text-align: center;
}

/* Title Size and Font */
#title
{
    font-size: 40px;
    font-family: Mv Boli, sans-serif, arial;
}

/* Description Size and Font */
#description
{
    font-size: 20px;
    font-family: Mv Boli, sans-serif, arial;
}

/* Background Image */
.background-image
{
      position: fixed;
      top: 0;
      bottom: 0;
      width: 100%;
      height: 100%;
      opacity: 0.5;
      z-index: -5000;
      background-image: url("https://material.angular.io/assets/img/examples/shiba2.jpg");
      background-repeat: no-repeat;
      background-size: cover;
}

/* Survey Form Styling */
#survey-form
{
    background: hsl(204, 94%, 65%);
    max-width: 500px;
    margin: 50px auto;
    padding: 25px;
}
<body>
  <h1 id="title">Survey Form for Tech</h1>
  <p id="description">Help us improve your experience!</p>

  <!-- Background Image -->
  <div class="background-image"></div>

  <!-- Survey Form -->
  <form id="survey-form">
      <div class="form-flow">
          <label for="name" id="name-label">Name</label>
          <input id="name" type="text" required="" placeholder="Enter your name">
      </div>
  </form>
</body>

The issue was resolved after discovering that there were conflicting URLs for the image source.

Check out the Updated Situation

Answer №1

Utilize the ::after pseudo-element to incorporate both a background image and set opacity in this scenario.

* {
  padding: 0;
  margin: 0;
}

.background-image{
  Position:fixed;
  Top: 0;
  Bottom: 0;
  Width: 100%;
  Height: 100%;   
}

.background-image:after {
  position: absolute;
  content: '';
  background: url('https://via.placeholder.com/150/0000FF/808080') no-repeat center center / cover;
  width: 100%;
  height: 100%;
  opacity: 0.5;
}

#survey-form {
  //background: hsl(204, 94%, 65%);
  background: red;
  padding: 0; 
  margin: 50px auto; 
  position: absolute; 
  z-index: 1; 
  width: 500px;
  height: 300px;
  left: 50%;
  transform: translateX(-50%);
  padding: 20px;
}
<div class="background-image">
    <div id="survey-form">
      <p>Text 1</p>
    </div>
  </div>

Answer №2

It demonstrates the transparency of the background.

Please ensure that your CSS styles are in lowercase letters.

https://example.com

* { margin: 0; padding: 0; }

body
{
    text-align: center;
}

/* Title Size and Font */
#title
{
    font-size: 40px;
    font-family: Mv Boli, sans-serif, arial;
}

/* Description Size and Font */
#description
{
    font-size: 20px;
    font-family: Mv Boli, sans-serif, arial;
}

/* Background Image */
/*background-image:after 
  {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    background-image: url(Tech.jpg);
    opacity: 0.25;
  }*/

.background-image
{
    position: fixed;
    top: 0;
    bottom: 0;   
    width: 100%;
    height: 100%; 
    opacity: 0.25;
    z-index: -5000;
    background-image: url("https://material.angular.io/assets/img/examples/shiba2.jpg");
    background-repeat: no-repeat;
    background-size: cover;
}

/* Survey Form Styling */
#survey-form
{
    background: hsl(204, 94%, 65%);
    max-width: 500px;
    margin: 50px auto;
    padding: 25px;      
}
<body>
  <h1 id="title">Survey Form for Tech</h1>
  <p id="description">Help us improve your experience!</p>

  <!-- Background Image -->
  <div class="background-image">

  </div>

  <!-- Survey Form -->
  <form id="survey-form">
      <div class="form-flow">
          <label for="name" id="name-label">Name</label>
          <input id="name" type="text" required="" placeholder="Enter your name">
      </div>
  </form>
</body>

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

Steps to create a direct download link for files stored on Amazon S3

I am trying to create a link that allows users to download a file stored on S3. <a href="https://s3.region.amazonaws.com/bucket/file.txt" download>Download</a> only displays file.txt in the browser. I discovered a way to ensure successful down ...

Using javascript to sift through data in a table

Currently, I have a table echoing an SQL query using PHP. $query="SELECT Name, Location, ID, Price From ProdTable where ID>=2300;" $results = mysql_query($query); while ($row = mysql_fetch_array($ ...

What is the best way to ensure the width of a DIV adjusts to its content before centering it?

I'm trying to make the width of the parent div adjust based on how many inline-block displayed boxes can fit in one row. When the parent div reaches 100% width and a box is too wide for the first row, it should drop down to the next line. That's ...

Eliminate the preset !important declarations within elements

I am currently facing a CSS conflict on my WordPress site caused by a prominent plugin. The developers of the plugin have scattered !important declarations across their style sheets, making it difficult for me as a developer to make necessary changes. Whil ...

The Geolocation API popup on Safari for iOS kept appearing repeatedly

I have successfully implemented a code using the HTML5 Geolocation API to retrieve the user's current position within a mobile website. Although the code functions properly, there is an issue with Safari on iOS. Whenever the page is reloaded, a syste ...

What could be causing my linear background to behave in this unusual manner?

Just when I thought styling my background with a simple line of code would be easy, I encountered an unexpected issue. Instead of a smooth linear-gradient from the top left to the bottom right, my background is showing rows of red and blue in between each ...

Executing PHP script out of echoing system

Can you help me figure out a solution for this issue I'm facing? I need to create an alert in PHP that calls JavaScript, but my PHP code is within a textarea. Is there a way to display the script outside of the textarea without having to move the PHP ...

Submitting a PHP form by uploading an image with AJAX

I'm looking to submit form data to a MySQL database using AJAX. While I'm not very familiar with AJAX, I managed to write a code that successfully submits text data to the database. However, I'm facing issues with uploading and storing image ...

Unusual anomalies observed in CSS navigation bar styling

During my CSS work on a navigation bar, I came across an unusual behavior. First Attempt: #nav li { display: inline-block; } #nav li { font-size: 1em; line-height: 40px; width: 120px; height: 40px; ...

A step-by-step guide to showcasing dates in HTML with Angular

I have set up two datepickers in my HTML file using bootstrap and I am attempting to display a message that shows the period between the first selected date and the second selected date. The typescript class is as follows: export class Datepicker { ...

Problem with scrolling in Firefox when inside an <a> block

My issue in Firefox is that I can't scroll by dragging the scrollbar within an <a> element: <a id="monther" class="single" href=""> <span>Month</span> <ul class="month" style="height:100px;width:200px;overflow:auto; ...

JavaScript Drag-and-Drop Statement Issues

Currently working on a JavaScript game that utilizes the drag and drop feature of HTML. The goal is to make randomly generated fruit images draggable and droppable onto a jelly image. When the dragged image matches a certain condition (e.g., when the numbe ...

Unable to apply height and width properties to CSS div

I've been facing an issue with applying height and width to div elements in my project. The tech stack I'm using includes TailwindCSS and Nextjs. My objective is to create vertically snap-scrolling slides, but the height and width properties see ...

Generating a business card example using node-html-pdf on an Ubuntu operating system

I am currently attempting to utilize the node-html-pdf module on Ubuntu 16.04 by following the businesscard example provided at https://github.com/marcbachmann/node-html-pdf. Regrettably, I encountered difficulties in generating the PDF file. To begin wi ...

Creating uniform heights for HTML column-based tables using divs in a React environment

I am developing a unique column-oriented and div-based table using React with Typescript. The data outside the table is organized in a column-based structure, rendering column 1 followed by row 1, row 2, row 3, then column 2 with its respective rows. The ...

What is the best way to toggle the navigation bar between opened and closed

I'm having trouble with this navbar not opening and closing properly. Can anyone suggest what script I should add? <nav class="navbar navbar-expand-md"> <a class="navbar-brand" href="/"> <img src=&qu ...

Stop the web browser from storing the value of the input control in its cache

Many web browsers have a feature that saves the information you enter into certain fields so you don't have to type it again. While this can be convenient for most cases, I am faced with a situation where users must input a unique reference for a new ...

Ways to prevent text from wrapping in CSS

I'm currently in the process of creating a new website and I've encountered an issue with my CSS. It seems that whenever there is a space present, the text inside h2 tags wraps unexpectedly. You can visit the site here. Here's the specific ...

Textbox value disappears after being updated

When I click on the edit link (name), the value from the database is displayed as a textbox. However, when I update another normal textbox (age), the value in the edit link textbox disappears. Strangely, if I input a new value into the edit link textbox, i ...

What could be the reason why the text inside the anchor tag is not showing up?

The text within the anchor tags, such as feature and pricing, is not visible on the webpage. I attempted to add a color attribute to change this but it did not have any effect. The only thing that changed was the cursor when hovering over the links, while ...