Struggling to create a flawless gradient fade transition

Looking to create a gradient overlay on my images for a specific effect:

The goal is to have the gradient darker at the bottom, while leaving the top unaffected by the darkness.

I attempted the following code:

@include linear-gradient(to top, rgba(0,0,0,0.4) 0%, rgba(255,255,255,1));

However, this resulted in a whitish effect at the top. I only want the gradient to darken the lower part of the image, without affecting the upper portion.

If anyone knows how to achieve this, please share your insights. Thank you!

Answer №1

If you're looking to create a cool gradient effect with CSS, check out this code snippet: http://jsfiddle.net/3sxd82nf/5/

    <div id="test">x</div>
    <div id="gradient"></div>

#test {
    position:absolute;
    top: 10px;
    left: 0px;
    width: 200px;
    height: 200px;
    background-image: url('http://images2.layoutsparks.com/1/198321/50s-diner-chick-squares.jpg');
}

#gradient {
    position:absolute;
    top: 10px;
    left: 0px;
    width: 200px;
    height: 200px;
    
    background: -moz-linear-gradient(top, rgba(0,0,0,0) 50%, rgba(0,0,0,1) 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(50%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,1)));
    background: -webkit-linear-gradient(top, rgba(0,0,0,0) 50%,rgba(0,0,0,1) 100%);
    background: -o-linear-gradient(top, rgba(0,0,0,0) 50%,rgba(0,0,0,1) 100%);
    background: -ms-linear-gradient(top, rgba(0,0,0,0) 50%,rgba(0,0,0,1) 100%);
    background: linear-gradient(to bottom, rgba(0,0,0,0) 50%,rgba(0,0,0,1) 100%);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000', endColorstr='#000000',GradientType=0);
}

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

"Enjoying the convenience of a stationary header while browsing on your smartphone

Hey there! I'm currently facing an issue with my website's fixed horizontal nav bar when zooming in on a mobile device. After doing some research, it seems the only solution is to implement some javascript. I came across a jquery fix (see below) ...

Blank space appearing at the bottom of webpage

I have a strange issue with my document where there is a small white gap at the end. Upon inspecting the element, it seems to be related to the body. Any suggestions on how to resolve this? ...

What is the best way to create a fixed footer in Next.js using React?

I'm looking to create a fixed footer that will stay at the bottom of the page if there isn't enough content to fill it. I've been researching ways to achieve this using CSS, but many of the methods don't easily translate to React/Next.j ...

What could be causing the background image on my element to not update?

I'm attempting to utilize a single background image that is 3 pixels wide and 89 pixels tall. Each vertical stripe of 1 pixel will serve as the background for a different div. I had presumed that adjusting the background-position by -1px 0 and specif ...

css subcategories - divs failing to meet css criteria

I am encountering an issue where my subclass is not working on DIV elements. While the CSS rules are able to match inline tags like span and a, they do not seem to work with div. Please refer to the example provided below: <style> .row { disp ...

What is the best way to eliminate the header and side navigation in a master page design?

I've set up a master page called wrap.master which is connected to multiple content pages. I'm looking to create a new content page and link it to the master page. However, I want this new content page to be independent from the header and side n ...

Centering an image that is absolutely positioned within a container that is relatively positioned, horizontally

Looking to center an image that is positioned absolutely horizontally within a container that is relatively positioned. After attempting with CSS and not finding success, I ended up using Jquery. http://jsfiddle.net/CY6TP/ [This is my attempt using Jquery ...

CSS, Assistance in incorporating a sub menu into a drop-down menu

I'm looking to enhance my drop down menu by adding a sub menu. Specifically, I would like to create a sub menu for Item 3 in the HTML below. How can I achieve this? Thank you, Below is my CSS code: .nav_menu { width:100%; background-color:# ...

What is the best way to share CSS styles between React and React Native?

Is it recommended to use inline CSS styles in a React / Next.js app to maintain code consistency across projects? For example, like this: import {StyleSheet, Dimensions} from 'react-native'; const vw = Dimensions.get('window').width / ...

css overflowing content can disrupt the layout of the screen

I am currently working on creating a modal that will be displayed in the center of the screen with the same width as the main page. However, I am facing an issue where the modal is not perfectly centered. I suspect that this is due to the overflow style ...

Could you advise on the best placement for my upcoming JQuery animation?

Here is the code I am currently working with: $(function() { $("button").click(function() { $("#box1").animate({ left: $(window).width() - 800 }, { complete: function() { $("#box1").hide(); } }); $("#box2").a ...

After installation, the Tailwind classes seem to be malfunctioning

Let me start by mentioning that although the title of this question is reminiscent of this other question on Stack Overflow, I have already tried the solutions provided there with no success. I initially attempted to set up Tailwind using their official C ...

What's the name of the auto-triggered dropdown menu feature?

Visit Amazon's official website Description: Within the 'Shop by Department' section- A drop-down menu that remains visible without requiring you to hover over it. However, when the browser is in a non-full-screen mode, the menu disappears ...

Achieve the appearance of table-like alignment without the need for traditional tables

Any ideas on how to achieve the following layout: <table border="0"> <tbody> <tr> <td style="margin-right:5px;"> <h2 id="optiona" class="option optiona optiona2">a. aa </h2> </td> ...

What is the best way to design unconventional grids using Bootstrap 4?

Is it possible to achieve unique grid layouts in Bootstrap 4? For instance, An irregular grid where the first column covers two rows, followed by two rows with three columns each |||||||||||||||| | | | | | | |_ |_ |_ | | | | | | |_____| ...

Showing text beside an image within a division

In my div, I have an image along with a paragraph and h6 text. My goal is to position the text on the right side of the image without it wrapping underneath. I've experimented with floating both left and right, clearing, setting display to inline-blo ...

What is the best way to insert an HTML data attribute string into a SCSS mixin using attr()?

I'm currently working on setting up a color scheme in SCSS that allows me to use the following HTML structure: <div class="swatch" data-bg="green">...</div> In my SCSS file, I have defined a mixin like this: @function color($key: ' ...

Display an icon to act as a separator between icons in CSS styling

Is there a way to display a spacer line before and after icons (cross symbols) while excluding the spacer line before and after buttons carrying the word "Cancel"? How can this be achieved? This is my CSS file: .Container > *:first-child::before, .Con ...

Customize URL based on selected button

My question may be a bit unclear, but I want to generate dynamic URLs that redirect users to specific pages based on the link clicked. For example: Parent page with links (a, b, c, x, y) User clicks on 'b' User is taken to a Node Page that play ...

Eliminating undesired borders of table cells using CSS

I am facing a unique and puzzling issue. Here is the simple markup: <table> <thead> <tr><th>1</th><th>2</th><th>3</th></tr> </thead> <tbody> <tr>< ...