Gradient overlay on element on the right side - css

I have created a container with elements that is scrollable. I want the element on the right side to have a gradient overlay. How can I create that with CSS?
.container {
display: flex;
flex-wrap: nowrap;
overflow-x: scroll;
width: 1000px;
}
.element {
min-width: 200px;
height: 100px;
background-color: red;
margin-right: 10px;
}
<div class="container">
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
</div>
https://codepen.io/naomilea/pen/RjZGaM

If you are just looking for the last element to have a gradient color, you can code your css like this:
.container {
display: flex;
flex-wrap: nowrap;
overflow-x: scroll;
width: 1000px;
}
.element {
min-width: 200px;
height: 100px;
background-color: grey;
margin-right: 10px;
}
.element:last-child
{
background: -webkit-linear-gradient(to right, grey, white);
background: -o-linear-gradient(to right, grey, white);
background: -moz-linear-gradient(to right, grey, white);
background: linear-gradient(to right, grey, white);
}
<div class="container">
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
<div class="element">
</div>
</div>
Check updated codepen

Add this to the div element you want to add the gradient style
.element {
background: red; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(left, red , white); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(left, red, white); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(left, red, white); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, red , white); /* Standard syntax */
}

Related

How can i skew 2 upper corners of a div and keep a round corners?

I'm trying to create the following tabs style. I've tried many directions - but none seems to works...
I've tried to use clip-path - but it's removes the round borders.
.wrapper {
display: flex;
}
.tab {
width:100px;
padding: 5px;
background-color: tomato;
text-align:center;
margin-right:5px;
border-top-left-radius:10px;
border-top-right-radius:10px;
//clip-path: polygon(10% 0%,90% 0%,100% 100%,0% 100%);
//transform-origin: 100% 50%;
//transform: perspective(100px);
}
<div class="wrapper">
<div class="tab">
1
</div>
<div class="tab">
2
</div>
<div class="tab">
3
</div>
</div>

How to make a gradient continue in other divs

I would like my gradient to pass on to the next div. Putting one div behind them with the gradient would probably work, but on my website the elements are not exactly next to eachother
.row {
clear: both;
}
.portrait {
width: 200px;
height: 200px;
background-color: red;
float: left;
}
.photo {
width: 200px;
height: 150px;
background-color: blue;
}
.gradient {
width: 200px;
height: 50px;
background-color: green;
}
<div class="row">
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
</div>
<div class="row">
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
</div>
Codepen:
https://codepen.io/chingwai/pen/poEGxBe
To explain my structure:
.portrait = is the container, this is dynamically created based on my database.
.photo = will be a profile photo
.gradient = This is where the gradient should come and continue to the other divs that contain .gradient As you can see .photo will be between the divs, so they are not postioned under eachother.
Give all the divs you want to be with the gradient BG:
background-image: linear-gradient(your choice);
background-repeat: no-repeat;
background-attachment: fixed;
.child{
height:120px;
width:120px;
border:solid 2px white;
background-image: linear-gradient(to right,pink,green);
background-repeat: no-repeat;
background-attachment: fixed;
}
.parent{
display:flex;
width: 250px;
}
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
EDIT
After your explanations on the comments and post edits. Do this:
.gradient{
width: 200px;
height: 50px;
background-image:linear-gradient(to right, blue, lightblue);
background-attachment:fixed;
}

CSS Two columns layout + gradient separation

I am trying to show a gradient vertical separation between two columns, and a bottom horizontal gradient separation between the divs.
The following code (scss) doesn't show the bottom border:
.col-container {
.column-box {
border-width: 2px;
border-style: solid;
border-image: linear-gradient(to right, white, #efedf4, white) 1 stretch;
min-height: 200px;
}
& > div:nth-child(odd) {
border-width: 2px;
border-style: solid;
border-image: linear-gradient(to bottom, white, #efedf4) 0 90%;
}}
While the following code only shows the bottom border:
.col-container {
.column-box {
border-width: 2px;
border-style: solid;
border-image: linear-gradient(to right, white, #efedf4, white) 1 stretch;
min-height: 200px;
}}
Here is the code, as you will see the left div losses its bottom border:
https://jsfiddle.net/0nsvzqxg/
Any idea how to show only the vertical separator in between the 2 divs and the bottom border on all of them?
Thanks
You have 2 things to solve.
draw the border on two sides but from the same gradient
select the right boxes via the nth-child() selector
Since the width of the border image is quiet small, the gradient can be drawn like a diagonal. from a top corner to the opposite bottom corner and repeated once . It could be linear-gradient(to bottom left, white, #efedf4, white, #efedf4, white).
while you need to draw one or 2 borders, you need to update the slice values for each borders. See https://developer.mozilla.org/en-US/docs/Web/CSS/border-image-slice
When four positions are specified, they create slices measured from the top, right, bottom, and left in that order (clockwise)
div {
border-width: 2px;
border-style: solid;
border-image: linear-gradient(to bottom left, red, blue, red, blue, red)1 / 2px 2px 2px 2px stretch;
/* what would be gradient image */
background: linear-gradient(to bottom/* or top */ left/* or right*/ , blue, red, blue, red, blue);
box-shadow: inset 0 0 0 2px white;/* break border from background */
/* demo purpose */
height: 50vh;
width: 50vw;
padding: 1em;
color: white;
}
html,
div {
display: flex;
align-items: center;
justify-content: center;
}
p {
margin: 1em;
padding: 1em;
}
html {
min-height: 100vh;
}
/* end demo */
<div>
<p>To figure out the gradient image needed for the border, you may draw it in the background to tune it</p>
<p> from horizontal / vertical to diagonal, it needs to be repeated at least once.</p>
</div>
Note: shorthand values : border-image:/* source | slice | width | outset | repeat */
About the nth-child() selector, you can use a counter CSS to see better where each child stands .
.col-container {
counter-reset: box
}
.column-box:nth-child(odd) {
color: tomato
}
.column-box::before {
counter-increment: box;
content: 'child N°:'counter(box)' ';
color: green
}
<div class="col-container">
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
Once put together, it can be :
.col-container {
overflow: auto;
}
.col-container > * {
float: left;
width: 50%;
box-sizing: border-box;
}
.col-container .column-box {
border-width: 2px;
border-style: solid;
border-image: linear-gradient(to bottom left, white, #efedf4, white, #efedf4, white)
2/ 0 0 2px 0 stretch;
min-height: 30vh;
}
.col-container > div:nth-child(odd) {
border-width: 2px;
border-style: solid;
border-image: linear-gradient(to bottom left, white, #efedf4, white, #efedf4, white)
2/0 2px 2px 0;
}
<div class="col-container">
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
<div class="column-box">
<div class="cover">
Image
</div>
</div>
</div>
Note: flex + flex-wrap would be a better option than float, each boxes of each rows will be the same height.

Apply gradient to bottom of container if height is greater than X pixels

Note: I am not simply asking how to put a gradient to the bottom of a div. I'm asking how to only show the gradient if the div is greater than a certain height.
I currently have this:
https://jsfiddle.net/fwtj44bj/3/
I want to apply this gradient to the bottom of any .container that is great than 100px in height:
http://www.colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&0+0,1+100
Meaning that the second row of the first .container should have the gradient over the boxes, but the second .container should have no gradient.
How can this be done?
My thinking is to somehow make use of max-height, but I'm not sure how.
HTML:
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
CSS:
.container {
width: 332px;
margin-bottom: 48px;
}
.box {
width: 100px;
height: 100px;
display: inline-block;
background: red;
margin-right: 8px;
}
You need javascript to get the height of div. after that you can set a class that will add gradient.
If you want gradient over boxes then we use ::after pseudo class.
have a look please
var heights = document.getElementsByClassName('container');
for (var i = 0; i < heights.length; i++) {
var height = heights[i].offsetHeight;
if(height > 104){
heights[i].className += " gradient";
}
}
.container {
width: 332px;
margin-bottom: 48px;
padding:0px;
position:relative;
}
.box {
width: 100px;
height: 100px;
display: inline-block;
background: red;
margin-right: 8px;
}
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&0+0,1+100 */
.gradient::after{
display:inline-block;
position:absolute;
z-index:999;
bottom:0px;
left:0px;
width:100%;
height:100%;
content:' ';
background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */
}
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
Without javascript. Use :after selector.Position your container as relative and then offset the :after element by 100px.
.container {
width: 332px;
margin-bottom: 48px;
position: relative;
}
.box {
width: 100px;
height: 100px;
display: inline-block;
background: red;
margin-right: 8px;
}
.container:after {
content: '';
position: absolute;
top: 100px;
left:0;
right: 0;
bottom: 0;
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%);
}
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
If you add jQuery to your project you can do this by adding a css class after checking each .container div's height.
https://jsfiddle.net/fwtj44bj/5/
$(".container").each(function(){
if ($(this).height() > 100) {
$(this).addClass("gradient");
}
});
Edit
I edited my answer so the pseudo element have height:calc(100% - 100px); instead of just height:100%, this way you don't need to have overflow:hidden on .container
How about this: check fiddle
.container{
width: 332px;
margin-bottom: 48px;
position:relative;
}
.container:after{
content:' ';
position:absolute;
bottom:0px;
width:100%;
height:calc(100% - 100px);
background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(255,0,255,1) 100%);
}
Obvious limitations: .container should have position:relative and overflow:hidden.

Bootstrap 3 Bleed left and right background images to edge of browser

This is what I'm trying to achieve. The top box with a background image that spans the whole browser width, and 2 content boxes inside centered. I've done that no problem.
I then need want 2 more boxes underneath, again centered, but each half needs a different backgkround image that should meet in the middle and bleed of to their respective edge. I am using bootstrap becuase I want these to stack on smaller screens. I can't figure out how this is possible. the black border represents the container. I can wrap the top bit in its own container which is fine, but I can't work out how to get the bottom bit to work, and I don't really want to use absolute positioning because it'll be a nightmare to get the responsive element to work.
Here is what I have so far
HTML:
<div class="fluid-full">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-6 left-half">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
<div class="col-md-6 right-half">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
</div>
</div>
CSS:
.example{
height: 200px;
border: 1px;
background-color: rgba(0,0,0,0.8);
padding: 30px;
border: 1px solid white;
color: white;
}
.fluid-full{
padding: 40px 0;
background-image: url(http://lorempixel.com/1920/400);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.left-half{
border-left: 25% solid transparent;
background-image: url(http://lorempixel.com/g/1000/400);
background-position: right;
background-repeat: no-repeat;
background-size: cover;
}
Checkout this Bootply
I need the top and bottom boxes to line up.
Any help appreciated.
I took you Bootply example and modified bottom bit to this:
<div class="col-md-6 fluid-half">
<div class="example col-md-6 pull-right">
<h1 class="text-center">LEFT</h1>
</div>
</div>
<div class="col-md-6 fluid-half">
<div class="example col-md-6 pull-left">
<h1 class="text-center">RIGHT</h1>
</div>
</div>
Here's the Bootply modification
Is this something you're trying to achieve?
OK, I've done it. Had to use some media queries.
HTML:
<div class="fluid-full">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid about-us">
<div class="row">
<div class="col-md-6">
<div class="sec-title text-center work-with-us">
<h2>Work With Us</h2>
</div>
</div>
<div class="col-md-6">
<div class="sec-title text-center what-we-do">
<h2>What We Do</h2>
</div>
</div>
</div>
</div>
CSS
.example{
height: 200px;
border: 1px;
background-color: rgba(0,0,0,0.8);
padding: 30px;
border: 1px solid white;
color: white;
}
.fluid-full{
padding: 40px 0;
background-image: url(http://lorempixel.com/1920/400);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.about-us .col-md-6 {
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(http://lorempixel.com/g/1000/400);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
padding: 70px 0;
}
.about-us .col-md-6 .sec-title {
margin-bottom: 0;
margin: 0 15px;
background-color: rgba(0, 0, 0, 0.8);
border: 1px solid white;
}
.about-us .col-md-6 .sec-title h2 {
color: #FFFFFF;
}
.about-us .col-md-6 .sec-title h2::after {
width: 70px;
}
#media (min-width: 768px) {
.about-us .col-md-6 .sec-title {
width: 720px;
margin: 20px auto;
}
}
#media (min-width: 992px) {
.about-us .col-md-6 .sec-title {
width: 455px;
margin: 0 15px;
}
}
#media (min-width: 1200px) {
.about-us .col-md-6 .sec-title {
width: 555px;
}
}
#media (min-width: 992px) {
.about-us .col-md-6 .work-with-us {
float: right;
}
}
Here is the bootply
Hopefully this might be useful to someone else too.

Resources