CSS - Transparency Gradient on an Image - css

I would like my background image to go from 100% opacity to 0% opacity. I could choose to use another image asset where I use an image editor to make the image fade opacity, however I want to use as little assets as possible. Can this be done with CSS? I know I could make several divs in which I change the opacity on each one, however this would require a lot of divs to make it look good.
This is what my code currently looks like with the solution I don't want to use:
<div class="contentFadeAway" id="cfa1"></div>
<div class="contentFadeAway" id="cfa2"></div>
<div class="contentFadeAway" id="cfa3"></div>
<div class="contentFadeAway" id="cfa4"></div>
<div class="contentFadeAway" id="cfa5"></div>
<div class="contentFadeAway" id="cfa6"></div>
<div class="contentFadeAway" id="cfa7"></div>
<div class="contentFadeAway" id="cfa8"></div>
<div class="contentFadeAway" id="cfa9"></div>
<div class="contentFadeAway" id="cfa10"></div>
And the CSS:
.contentFadeAway {
display: block;
position: fixed;
top: 160px;
padding: 0px;
width: 100%;
height: 5px;
background: url('/assets/shapeimage_3_int.png') fixed;
background-size:cover;
z-index: +1;
}
#cfa1 { top: 160px; opacity: 1; }
#cfa2 { top: 165px; opacity: .9; }
#cfa3 { top: 170px; opacity: .8; }
#cfa4 { top: 175px; opacity: .7; }
#cfa5 { top: 180px; opacity: .6; }
#cfa6 { top: 185px; opacity: .5; }
#cfa7 { top: 190px; opacity: .4; }
#cfa8 { top: 195px; opacity: .3; }
#cfa9 { top: 200px; opacity: .2; }
#cfa10 { top: 205px; opacity: .1; }
For those that don't understand what that code is doing it is here: http://jsfiddle.net/FVNY7/2/ I have a background image, and I want the content to fade away when it scrolls up, so I would have the same image with an opacity from 1 to 0 to give that effect. If the background was a solid color I could just use a rgba gradient, but its an image.

For the most cross-browser support, set your background image in your div. Then overlay another div with a semi-transparent gradient background on top of it.
HTML:
<div class="content"></div>
<div class="FadeAway"></div>
CSS:
.content{ position:absolute; top:0px; left:0px; width:100%; height:100%; background:url('http://upload.wikimedia.org/wikipedia/commons/thumb/0/0c/GoldenGateBridge-001.jpg/400px-GoldenGateBridge-001.jpg') no-repeat; }
.FadeAway{
position: absolute; top:0px; left:0px; width:100%; height:100%;
background:transparent;
background: linear-gradient(top, rgba( 255, 255, 255, 255 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background: -moz-linear-gradient(top, rgba( 255, 255, 255, 0) 0%, rgba( 255, 255, 255, 1 ) 100% );
background: -ms-linear-gradient(top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background: -o-linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
background: -webkit-linear-gradient( top, rgba( 255, 255, 255, 0 ) 0%, rgba( 255, 255, 255, 1 ) 100% );
-ms-filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#550000FF, endColorstr=#550000FF);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00ffffff, endColorstr=#ffffffff);
}
Here's a fiddle of the above example: http://jsfiddle.net/FVNY7/

Although it may not be the best implementation and there could be a better way the best way I have found is the down and dirty implementation that I mentioned in my question. Using PHP code it can be more refined and look good. Here is the code:
<style>
.contentFadeAway {
display: block;
position: fixed;
top: 160px;
padding: 0px;
width: 100%;
height: 1px;
background: url('/assets/shapeimage_3_int.png') fixed;
background-size:cover;
z-index: +1;
}
</style>
<?php
for ($int = "1"; $int <= "50"; $int++) {
echo "<div class=\"contentFadeAway\" style=\"top: " . (160 + 1 * $int) . "px; opacity: " . (1 - .02 * $int) . ";\"></div>\";
";
}
?>

My solution to my problem is to simply state that this is not possible with the current technology. An alternative option would be to use a simple transparency gradient. Until A better solution arrises this is what I will end up doing.
background: linear-gradient(to bottom, rgba(0,0,0,1) 0%,rgba(0,0,0,0) 100%);

Related

Is it possible to do this shape CSS?

I was asked with making such a background on a responsive site. I thought about preparing two divs using gradient, but it is highly problematic. Is it even possible to do it? Using this as a background-image is cumbersome for higher and lower resolutions.
Any ideas?
some clip-path and pseudo element can approximate this:
.box {
width: 300px;
aspect-ratio: .8;
position: relative;
z-index: 0;
}
.box:before,
.box:after {
content: "";
position: absolute;
z-index: -1;
inset: 0;
}
.box:before {
clip-path: polygon(0 0, 100% 50%, 10% 100%,0 100%);
background: linear-gradient(40deg, #3185c5, #0ea1b1);
}
.box:after {
clip-path: polygon(100% 30%, 100% 50%, 10% 100%,0% 100%, 0 80%);
background: linear-gradient(40deg, #3185c5, #f55778);
}
<div class="box"></div>

How can I combine gradients on to work on opposite axes?

Essentially, I want to create an element that combines a "to right" gradient with a color stop at a certain percentage and another color stop for the remaining width with a "to bottom" gradient that fades both colors to transparent. Getting the color stop part is easy, getting the fade is easy; I just can't figure out how to get both.
/*I can get this:*/
div {
width: 500px;
height: 100px;
}
.color-change {
background: linear-gradient(to right, rgb(255, 175,157) 80%, rgb(255, 95, 89) 80%);
}
/*or this:*/
.fade {
background:linear-gradient(to bottom, rgba(252, 193, 176, 0), #fcc1b0);
/* but not both*/
<div class="color-change"></div>
<div class="fade"></div>
This probably isn't hard but I can't find any examples that do exactly this. I could just use a png., but it seems as though this ought to be doable in CSS. Thanks for any suggestions (or better, solutions).
Use CSS ::before (:before)
In CSS, ::before creates a pseudo-element that is the first child of
the selected element. It is often used to add cosmetic content to an
element with the content property. It is inline by default. https://developer.mozilla.org
div {
width: 500px;
height: 100px;
}
.fade {
background: linear-gradient(to bottom, rgba(252, 193, 176, 0), #fcc1b0);
position: relative;
}
.fade::before {
display: inline-block;
content: "";
height: 100%;
width: 20%;
background: black;
position: absolute;
right: 0;
background: linear-gradient(0deg, rgba(246,115,115,1) 4%, rgba(250,192,194,1) 34%, rgba(255,233,234,1) 66%, rgba(255,255,255,1) 100%);
}
<div class="fade"></div>
Multiple background layer can do it:
.color-change {
--p:80%; /* this is your percentage */
background:
linear-gradient(to bottom, transparent, #fcc1b0) left,
linear-gradient(to bottom, transparent, rgb(255, 95, 89)) right;
background-repeat:no-repeat;
background-size:var(--p) 100%,calc(100% - var(--p)) 100%;
width: 500px;
height: 100px;
margin:10px;
}
<div class="color-change"></div>
<div class="color-change" style="--p:50%"></div>
<div class="color-change" style="--p:20%"></div>
Or you can mask it with a pseudo element. This is real transparent.
body {
background: dodgerblue;
}
div {
width: 500px;
height: 100px;
}
.color-change {
-webkit-mask: linear-gradient(to bottom, transparent, #000);
mask: linear-gradient(to bottom, transparent, #000);
position: relative;
}
.color-change:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: linear-gradient(to right, rgb(255, 175, 157) 80%, rgb(255, 95, 89) 80%);
}
<div class="color-change"></div>

CSS - image with overlays/background blurred diagonal

I want that the parts that are "whited" to get the image blurred.
I've tried using pseudo elements ::after and ::before to add the overlays but could only blurred the overlay.
tried with borders 2nd example codepen, but no sucess because with the transparent it creates a "square".
https://codepen.io/giventofly/pen/RQpqYZ
.hero-image {
width: 1280px;
height: 800px;
background-image: linear-gradient(rgba(46, 51, 82, 0.6) 100%, transparent 0), linear-gradient(125deg, rgba(255, 255, 255, 0.5) 35%, transparent 0), linear-gradient(-55deg, rgba(255, 255, 255, 0.5) 25%, transparent 0),
url('https://cdn.vox-cdn.com/thumbor/NU6lcSN3DGmjF7NhZp6ixY3HxgQ=/0x0:1620x1080/1200x800/filters:focal(0x0:1620x1080)/cdn.vox-cdn.com/uploads/chorus_image/image/46510678/Tarmogoyf_DGM_1920x1080_Wallpaper.0.0.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
z-index: 10;
}
<div class="hero-image"></div>
I only want to blur the part of the image that is "behind" the white linear-gradient
I'm sure someone can refine this approach a bit, but the main takeaways are:
Include the image twice in a container element.
Stack the two images.
Blur one and place it on the bottom.
Use clip-path on the top image to display the non-blurred region.
Insert a frost layer (transparent white) with a pseudo element of the container element between the two images.
Control layering with positioning and z-index.
.img-overlay {
display: inline-flex;
position: relative;
overflow: hidden;
}
.img-overlay::before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba( 255, 255, 255, 0.5 );
z-index: 1;
}
.img-overlay img:first-child {
position: absolute;
top: 0;
left: 0;
filter: blur( 3px);
z-index: 0;
}
.img-overlay img:last-child {
position: relative;
z-index: 2;
-webkit-clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
}
<div class="img-overlay">
<img src="http://unsplash.it/400/400?image=16">
<img src="http://unsplash.it/400/400?image=16">
</div>
You can use clip-path for this. The idea is to have two similar layer, the top with the clip-path to show only the needed part and keep the blur on the bottom layer visible. You can switch the blur between both element if you want to blur the middle part instead:
.hero-image {
width: 600px;
height: 250px;
position: relative;
overflow: hidden;
}
.hero-image:after,
.hero-image:before {
content: "";
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
background: center/cover no-repeat;
background-image:
linear-gradient(rgba(46, 51, 82, 0.6) 100%, transparent 0),
linear-gradient(125deg, rgba(255, 255, 255, 0.5) 35%, transparent 0),
linear-gradient(-55deg, rgba(255, 255, 255, 0.5) 25%, transparent 0),
url('https://picsum.photos/id/1024/800/800');
}
.hero-image:before {
filter: blur(4px);
}
.hero-image:after {
clip-path: polygon(45% 0, 97% 0, 68% 100%, 16% 100%);
}
<div class="hero-image"></div>

Shaped background

I would like to make some background shapes on my website ...
this is the look that I want
I have tried using the method with rotated/skewed rectangles, it works perfect just when I have only one color on the section below (because I can use the same color for the shapes). If I want to use a texture like in the image attached I will end up having this depending on what method I use. I have also tried using a svg for making the shapes, but I'm not sure if it's the best solution. I'm wondering if there is a clever way to do this. I realize maybe I'm not as clear as a should be, but thank you for finding time to read this.
You'll probably want to experiment with SVGs and masks, depending upon how complicated your shapes are going to be. You can find some great guidance here: https://www.sitepoint.com/masking-in-the-browser-with-css-and-svg/.
Illustrator can be saved as an SVG, but if you're using Sketch it's even easier! You'll notice the code outputs individual coordinates.
You can see a decent demo here: http://cssplant.com/clip-path-generator
This a concept. Try self to work project.
* {
margin: 0;
padding: 0;
}
.wrapper {
width: 100vw;
padding-top: 50%;
position: relative;
background-image: linear-gradient(90deg, rgba(0, 0, 0, .5) 66.6666667%, rgba(255, 255, 0, .6) 66.6666667%), url(http://beerhold.it/1200/600);
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
}
.wrapper:nth-child(2) {
background-image: linear-gradient(90deg, rgba(255, 255, 255, .7) 0, rgba(255, 255, 255, .7) 100%), url(http://beerhold.it/1400/700);
}
.topleft,
.topright,
.bottomleft,
.bottomright {
position: absolute;
top: 0;
height: 100%;
}
.topleft {
left: 0;
top: 40%;
width: 66.66666667%;
background-image: linear-gradient(transparent 0, transparent 50%, #fff 50%, #fff);
transform: skewY(7deg);
}
.topright {
left: 66.66666667%;
width: 33.33333334%;
top: 42.3%;
background-image: linear-gradient(transparent 0, transparent 50%, #fff 50%, #fff);
transform: skewY(-10deg);
}
.bottomleft {
left: 0;
top: -94%;
width: 33.33333334%;
background-image: linear-gradient(180deg, transparent 0, transparent 50%, #fff 50%, #fff );
transform: skewY(-10deg);
}
.bottomright {
left: 33.33333334%;
width: 66.66666667%;
top: -92%;
background-image: linear-gradient(180deg, transparent 0, transparent 50%, #fff 50%, #fff);
transform: skewY(7deg);
}
<div class="wrapper">
<div class="topleft"></div>
<div class="topright"></div>
</div>
<div class="wrapper">
<div class="topleft"></div>
<div class="topright"></div>
<div class="bottomleft"></div>
<div class="bottomright"></div>
</div>

How to vertically align a progress bar in Twitter Bootstrap?

I'm using the progressbar control of twitter-bootstrap.
I want to align it vertically to look like in the following image:
I found this thread, but I'm afraid it does not work now.
So I do this: http://tinker.io/e69ff/2
HTML
<br>
<div class="progress vertical">
<div class="bar bar-success" style="width: 70%;"></div>
<div class="bar bar-warning" style="width: 20%;"></div>
<div class="bar bar-danger" style="width: 10%;"></div>
</div>
CSS
.progress.vertical {
position: relative;
width: 20px;
min-height: 240px;
float: left;
margin-right: 20px;
background: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border: none;
}
Do you have any tip or advice to get it? If you need more info, let me know and I'll edit the post.
Bootstrap 3 and Bootstrap 4 solution.
Demo: https://jsfiddle.net/elijahmurray/7tgh988z/
I struggled with finding a good solution to this problem for awhile. Ultimately, I ended up writing my own that is semantically similar to how Bootstrap structures their progress bars.
This solution also doesn't use transform, which I found really messed up a lot of things with positioning when using it. Not to mention, it just got confusing with that.
HTML
<div class="progress progress-bar-vertical">
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="height: 60%;">
<span class="sr-only">60% Complete</span>
</div>
</div>
CSS
.progress-bar-vertical {
width: 20px;
min-height: 100px;
margin-right: 20px;
float: left;
display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6, BB7 */
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Safari 6.1+. iOS 7.1+, BB10 */
display: flex; /* NEW, Spec - Firefox, Chrome, Opera */
align-items: flex-end;
-webkit-align-items: flex-end; /* Safari 7.0+ */
}
.progress-bar-vertical .progress-bar {
width: 100%;
height: 0;
-webkit-transition: height 0.6s ease;
-o-transition: height 0.6s ease;
transition: height 0.6s ease;
}
Vote if this was helpful!
Bootstrap 2
Note this is a solution for bootstrap 2:
width 100%, height variable:
<br>
<div class="progress vertical">
<div class="bar bar-success" style="height: 70%;width:100%"></div>
<div class="bar bar-warning" style="height: 20%;width:100%"></div>
<div class="bar bar-danger" style="height: 10%;width:100%"></div>
</div>
Bootstrap 3+
I'd like you to refer to the others comments on this page
this will work:
.progress{
transform: rotate(-90deg);
}
http://codepen.io/mcgraw/pen/eCwvu
Changing the twitter bootstrap progress bar and animation from horizontal position to vertical position
========================================================================
HTML
<div class="progress progress-vertical progress-striped active progress-success">
<div class="bar" style="width: 40px;"></div>
</div>
<div class="progress progress-vertical progress-striped active progress-danger">
<div class="bar" style="width: 40px;"></div>
</div>
CSS
.progress-vertical {
position: relative;
width: 40px;
min-height: 240px;
float: left;
margin-right: 20px; }
Modify The Twitter bootstrap.css file as specified below:
#-webkit-keyframes progress-bar-stripes {
from {
background-position: 0 40px;
}
to {
background-position: 0 0;
}
}
#-moz-keyframes progress-bar-stripes {
from {
background-position: 0 40px;
}
to {
background-position: 0 0;
}
}
#-ms-keyframes progress-bar-stripes {
from {
background-position: 0 40px;
}
to {
background-position: 0 0;
}
}
#-o-keyframes progress-bar-stripes {
from {
background-position: 0 0;
}
to {
background-position: 0 40px;
}
}
#keyframes progress-bar-stripes {
from {
background-position: 0 40px;
}
to {
background-position: 0 0;
}
}
Change background-repeat to repeat-y and the degrees to 0deg. so, that the animation renders vertically
.progress-danger .bar,
.progress .bar-danger {
background-repeat: repeat-y;
}
.progress-danger.progress-striped .bar,
.progress-striped .bar-danger {
background-color: #ee5f5b;
background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(0.25, rgba(255, 255, 255, 0.15)), color-stop(0.25, transparent), color-stop(0.5, transparent), color-stop(0.5, rgba(255, 255, 255, 0.15)), color-stop(0.75, rgba(255, 255, 255, 0.15)), color-stop(0.75, transparent), to(transparent));
background-image: -webkit-linear-gradient(0deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -moz-linear-gradient(0deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: -o-linear-gradient(0deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-image: linear-gradient(0deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
}
Follow the same with the other progress types like success,warning etc and achieve vertical twitter bootstrap progress bars and animations...!
For you have any queries let me know I may help you..!
If any one out there have any optimized solution than this then please let me know..!
Don't forget to support this solution..!
Enjoy!
For the main progress class add the following
.progress{
display: flex;
flex-direction: column-reverse;
}
CSS
.progress{
position: absolute;left:50.5%;top:40%;width: 2.5%;height:50%;opacity: 0.8; filter: alpha(opacity=80);
}
.progress-bar{
position:absolute;top:20%; width: 100%;height: 80%;
}
See complete Code and implementation here

Resources