The opacity attribute in CSS is not producing the desired outcome

After numerous attempts, I have yet to successfully create the desired effect on the screen I am currently working on:

https://i.sstatic.net/BonQa.png

My goal is to achieve a transparent effect using a gradient as a background, but so far my efforts have been unsuccessful. I have experimented with the linear-gradient() function in CSS and adjusting the opacity, but the result was not what I had hoped for:

https://i.sstatic.net/vbIGW.png

I also tried incorporating a transparent SVG with the same gradient, as well as utilizing the SVG with reduced opacity, but unfortunately, these attempts also did not yield the desired outcome:

https://i.sstatic.net/10voI.png

https://i.sstatic.net/oaQIm.png

Below is the CSS and HTML code that I have been using:

        .login-section {
    
        .card {
            position: absolute;
            top: 30%;
            box-shadow: 1px 3px 9px 3px rgba(142, 142, 142, 0.19);
            border-radius: 10px 10px 10px 10px;
            min-height: 300px;
        }
    
        .gradient {
            background: url(../../../../assets/images/login.svg);
        }
    
        .login-form {
        }
    
        .logo {
            max-height: 100px;
        }
    }
 <section class="login-section d-flex flex-row justify-content-center">
    <div class="card w-100 border-0">
        <div class="card-body row p-0 mx-0">
            <div class="col gradient d-flex flex-column justify-content-center">
                <div class="d-flex flex-row justify-content-start pb-4">
                   <img src="" alt="">
                </div>
                <h5 class="text-white">Lorem Ipsum Dolor Sit Amet Lorem Ipsum</h5>
            </div>
            <div class="col login-form py-4 px-5">
                <p color="#636363" class="d-flex justify-content-center">Seja bem-vindo</p>
                <form>
                    <div class="form-group">
                        <label for="exampleInputEmail1">Email address</label>
                        <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp"
                            placeholder="Enter email">
                        <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone
                            else.</small>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword1">Password</label>
                        <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
                    </div>
                    <button type="submit" class="btn btn-primary w-100">Submit</button>
                </form>
            </div>
        </div>
    </div>
</section>

Answer №1

If you want to create a mask effect on an image, you can utilize the mask property. This property is considered experimental, so make sure to check the browser support here.

picture{
  display:inline-block;
  position:relative;
  
}
picture::after{
 content:"";
 position:absolute;
 top:0;
 left:0;
 width:100%;
 height: 100px;
 background: red;
 -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1), rgba(0,0,0,0));
  -webkit-mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
}
<picture>
<img src="https://www.gstatic.com/webp/gallery/1.sm.jpg"/>
</picture>

Answer №2

Give this CSS code a try

.grad{
background: rgba(212,228,239,1);
background: -moz-linear-gradient(left, rgba(212,228,239,1) 0%, rgba(134,174,204,0.49) 100%);
background: -webkit-gradient(left top, right top, color-stop(0%, rgba(212,228,239,1)), color-stop(100%, rgba(134,174,204,0.49)));
background: -webkit-linear-gradient(left, rgba(212,228,239,1) 0%, rgba(134,174,204,0.49) 100%);
background: -o-linear-gradient(left, rgba(212,228,239,1) 0%, rgba(134,174,204,0.49) 100%);
background: -ms-linear-gradient(left, rgba(212,228,239,1) 0%, rgba(134,174,204,0.49) 100%);
background: linear-gradient(to right, rgba(212,228,239,1) 0%, rgba(134,174,204,0.49) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d4e4ef', endColorstr='#86aecc', GradientType=1 );
}

Answer №3

Utilize the feature of Opacity in CSS on the div that houses the image:

It's important to note that opacity will impact the entire div, so I recommend creating a separate div for the background properties and another for the content. This Article (See solution 4 in the article for the most effective approach) details exactly how to achieve the visual effects you are looking for

        .login-section {
    
        .card {
            position: absolute;
            top: 30%;
            box-shadow: 1px 3px 9px 3px rgba(142, 142, 142, 0.19);
            border-radius: 10px 10px 10px 10px;
            min-height: 300px;
        }
    
        .gradient {
            background: url(../../../../assets/images/login.svg);
            opacity: 0.5;
        }
    
        .login-form {
        }
    
        .logo {
            max-height: 100px;
        }
    }
 <section class="login-section d-flex flex-row justify-content-center">
    <div class="card w-100 border-0">
        <div class="card-body row p-0 mx-0">
            <div class="col gradient d-flex flex-column justify-content-center">
                <div class="d-flex flex-row justify-content-start pb-4">
                   <img src="" alt="">
                </div>
                <h5 class="text-white">Lorem Ipsum Dolor Sit Amet Lorem Ipsum</h5>
            </div>
            <div class="col login-form py-4 px-5">
                <p color="#636363" class="d-flex justify-content-center">Seja bem-vindo</p>
                <form>
                    <div class="form-group">
                        <label for="exampleInputEmail1">Email address</label>
                        <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp"
                            placeholder="Enter email">
                        <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone
                            else.</small>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword1">Password</label>
                        <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
                    </div>
                    <button type="submit" class="btn btn-primary w-100">Submit</button>
                </form>
            </div>
        </div>
    </div>
</section>

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

Is it possible to move the Material UI TableSortLabel Arrow to the opposite side?

My table has columns that are both right aligned and left aligned, and I need them sorted. When the column is right aligned, I would like the sorting icon to be on the left side of the header. Otherwise, there is an awkward empty space where the icon shoul ...

Angular has trouble displaying information across multiple HTML files

I have created an HTML file to display some data. The initial HTML file named disc-log.html looks like this: <div> <h2>Discs</h2> <jhi-alert></jhi-alert> <div class="container-fluid"> <div class=" ...

Switch between displaying the HTML login and register forms by clicking a button

Currently, I am working on a website that requires users to either log in or register if they do not have an account. Below is the code I have developed for the login page: <span href="#" class="button" id="toggle-login">Log in</span> <di ...

Setting a bookmark feature in HTML using localStorage: A step-by-step guide

I'm working on a simple code that captures the text content of a dynamically updated <h1> element and stores it as a "bookmark" in localStorage. I want to enable users to save or delete the bookmark by clicking a button. Below is a basic version ...

The confirmation dialogue is malfunctioning

Need some assistance with my code. I have a table where data can be deleted, but there's an issue with the dialog box that pops up when trying to delete an item. Even if I press cancel, it still deletes the item. Here is the relevant code snippet: ec ...

A guide to disabling daily checkboxes and retrieving the chosen values using Angular.js

Within a single table, I have incorporated a dynamic drop-down list that spans over 7 days. Additionally, I have implemented a "+" button that allows for the creation of additional rows dynamically for each day. Each row within the table features a checkb ...

JavaScript only collapsible navigation bar

I have implemented a collapsible navbar using Bootstrap 4 framework according to the documentation provided at this link. The navbar and its contents collapse on small screens, including smartphones, by adding the class .collapse.navbar-collapse. You can ...

Using jQuery and Modernizr for CSS3 and Javascript transitions support in Internet Explorer

Looking for a way to add support for button hover effects in IE 7-9 on this Codepen.io project. Can anyone help? For example, I'm trying: transition-duration: 0.5s; transition-property: all; transition-timing-function: ease; margin-top: 5px; I atte ...

Basic jQuery template design

Currently, I am developing a user interface that allows users to add or delete items with a similar layout. The process starts with one item and by clicking 'add', more items can be added. These items come in several different types. My current ...

How can I include an HTML tag within a select input value in a React.js project?

I am facing an issue while trying to map values from the input field of a select tag. It seems to be returning [Object object] for some reason. When I do not include another tag in the return statement of the map function, the output works fine. However, I ...

Ensure the div element remains fixed at the top of the page

I created a script to identify when I reach the navigation bar div element and then change its CSS to have a fixed position at the top. However, I am encountering an issue where instead of staying fixed, it jumps back to the beginning of the screen and fli ...

An error occurred: TypeError - Unable to access the 'value' property of a null object during a value change

Example ImageCreating a dynamic form where rows and select box options are added dynamically using 'x' and 'i' increment values in two JavaScript functions. The code works fine when the option selected is 0.5, but throws an error Uncaug ...

Tips on making scrollable content within a static div element

I am currently working on designing a shopping cart layout for a website that allows users to order food from a restaurant. I want the shopping cart to remain fixed on the screen, but be scrollable when there is an overflow of items being added. This is a ...

I am looking to implement a required alert for a radio button that mimics HTML5. How can

When using the input type text, adding the required attribute prevents the form from submitting and prompts the browser to focus on the required field with an alert instructing to fill it out. On the other hand, when applying the required attribute to t ...

Looking for assistance in using JavaScript to determine the percentage of a DIV's width in pixels

Using PHP, I am generating boxes whose width is set to 100% of a container in CSS. Now, I want to determine the equivalent pixel value of that box... HTML <div class="masonry" > <? while($row = $stmt->fetch()){ ?> <div class="i ...

dispatch email display Twitter Bootstrap notification utilizing Ajax

I'm trying to set up an email sending feature via a contact form. I want it to send the email and display a Bootstrap alert confirming that the email has been sent. Below is the HTML code: https://jsfiddle.net/6rfeas35/. Additionally, here is my PHP c ...

What steps should I take to prevent my <mat-card> from expanding whenever messages are shown in Angular 9?

I have a <mat-card> containing a login form on my page. However, when error messages are displayed, the vertical size of the <mat-card> changes and I need it to remain the same. Is there a way to prevent this from happening? Below, you will ...

Video upload issue in PHP while images are successfully uploaded

I have a form that successfully uploads images, but it's not working when I try to upload a video. What changes should I make to allow video uploads through this form? $videoform = " <form action='' method='post' enctype=&a ...

Exploring the power of CSS using :after and :nth-child selectors

.app-btn { font-size: 0px !important; } .app-btn:after { content: '+2500'; visibility: visible; font-size: 15px !important; } .app-btn:after:nth-child(1) { content: "+18000"; } .app-btn:after:nth-child(2) { content: "+14000"; } < ...

Incomplete filling of the SVG element is observed

Trying to animate SVG text to display only the outer stroke of each letter initially, followed by filling the interior with color. However, after the animation finishes, there are unfilled spaces left. Is there a property that can be applied to the SVG o ...