I'm trying to make 2 gradients overlap each other at the same time with this code...
#grad1 {
height: 3px;
background: -webkit-linear-gradient(left, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%);
background: -o-linear-gradient(left, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%);
background: -moz-linear-gradient(left, rgba(0,0,0,0) 0%, rgba(0,0,0,0.65) 100%);
background: linear-gradient(to right, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%);
}
#grad2 {
height: 3px;
background: -webkit-linear-gradient(left, #2184E2 , #AE1937);
background: -o-linear-gradient(right, #2184E2, #AE1937);
background: -moz-linear-gradient(right, #2184E2, #AE1937);
background: linear-gradient(to right, #2184E2 , #AE1937);
}
But it doesn't overlap each other like I want it to.
How can I make #grad1 overlap #grad2 so they're both visible at the same time?
Use this way:
#grad1 {
position: absolute;
z-index: 1;
}
#grad2 {
position: absolute;
z-index: 2;
}
This way it just overlaps both the stuff, keeping the #grad2 on top of #grad1. Make sure, you have another <div>, which is the parent of both having a position: relative to it.
Snippet
#grad1 {
height: 3px;
background: -webkit-linear-gradient(left, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%);
background: -o-linear-gradient(left, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%);
background: -moz-linear-gradient(left, rgba(0,0,0,0) 0%, rgba(0,0,0,0.65) 100%);
background: linear-gradient(to right, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%);
}
#grad2 {
height: 3px;
background: -webkit-linear-gradient(left, #2184E2 , #AE1937);
background: -o-linear-gradient(right, #2184E2, #AE1937);
background: -moz-linear-gradient(right, #2184E2, #AE1937);
background: linear-gradient(to right, #2184E2 , #AE1937);
}
#grad1 {
position: absolute;
z-index: 1;
}
#grad2 {
position: absolute;
z-index: 2;
}
.parent {position: relative; width: 50px; height: 50px;}
.parent > div {width: 50px;}
<div class="parent">
<div id="grad1"></div>
<div id="grad2"></div>
</div>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How can I achieve a design like this with CSS3. I tried to give it a very high transparent border but that makes the taper outwards and not inwards.
It looks like something that can be achieved with CSS that is why I am reluctant to use images for this.
I would suggest using :before and :after to 'cover' parts of your gradient'ed div.
The problem is that borders dont support '%' as standard. So you'll have to use #media queries if your div needs to be responsive to change out the width of the borders, like below.
JSFiddle
HTML
<div id="angled"></div>
CSS
body{
margin:0;
padding:0;
}
#angled{
background: #6393c1;
background: -moz-linear-gradient(top, #6393c1 0%, #cfe7fa 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6393c1), color-stop(100%,#cfe7fa));
background: -webkit-linear-gradient(top, #6393c1 0%,#cfe7fa 100%);
background: -o-linear-gradient(top, #6393c1 0%,#cfe7fa 100%);
background: -ms-linear-gradient(top, #6393c1 0%,#cfe7fa 100%);
background: linear-gradient(to bottom, #6393c1 0%,#cfe7fa 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6393c1', endColorstr='#cfe7fa',GradientType=0 );
width:500px;
margin:0 auto;
height:200px;
position:relative;
}
#angled:before,
#angled:after{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
content:" ";
height:0;
left:0;
right:0;
position:absolute;
bottom:0;
}
#angled:after{
border:30px solid rgba(255, 255, 255, 0);
border-bottom-width:0;
border-left-width:200px;
border-left-color:white;
}
#angled:before{
border:60px solid rgba(255, 255, 255, 0);
border-bottom-width:0;
border-right-width:300px;
border-right-color:white;
}
#media (min-width:800px){
#angled{
width:800px;
}
#angled:after{
border-left-width:350px;
}
#angled:before{
border-right-width:450px;
}
}
#media (min-width:1200px){
#angled{
width:1200px;
}
#angled:after{
border-left-width:500px;
}
#angled:before{
border-right-width:700px;
}
}
gradient generated using Ultimate CSS Gradient Generator
The below should give you a starting point, the key is creating triangles using the borders of a divs :before and :after pseudo elements.
Demo Fiddle
HTML
<div></div>
CSS
html, body, div {
width:100%;
margin:0;
padding:0;
}
div {
height:100px;
width:600px;
background:#007bff;
}
div:before, div:after {
content:'';
position:absolute;
display:block;
}
div:before {
width: 0px;
height: 0px;
top:100px;
border-style: solid;
border-width: 0px 200px 50px 0;
border-color: transparent #007bff transparent transparent;
}
div:after {
width: 0px;
height: 0px;
border-style: solid;
border-width: 0px 0 50px 400px;
border-color: transparent transparent transparent #007bff;
top:100px;
left:200px;
}
looks good so no?
I leave an example
http://jsfiddle.net/jdQaA/1/
header{
display:inline-block;
background: white;
text-align: center;
width: 100%;
}
.main{
display:inline-block;
width: 1024px;
margin:0 auto;
min-height: 100px;
background: #1e5799; /* Old browsers */
background: -moz-linear-gradient(top, #1e5799 0%, #7db9e8 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* IE10+ */
background: linear-gradient(to bottom, #1e5799 0%,#7db9e8 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
position:relative;
}
.main:before{
content: '';
position: absolute;
top: 100%;
left: 100px;
height: 1px;
width: 100%;
border-left: 924px solid #7db9e8;
border-bottom: 50px solid transparent;
}
.main:after{
content: '';
position: absolute;
top: 100%;
left: 0px;
height: 1px;
width: auto;
border-left: 100px solid #7db9e8;
border-bottom: 50px solid transparent;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.container{
width: 1024px;
display:inline-block;
}
.submain{
float:right;
position: relative;
top: 60px;
width: 300px;
height: 300px;
background: #7db9e8; /* Old browsers */
background: -moz-linear-gradient(top, #7db9e8 0%, #1e5799 97%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#7db9e8), color-stop(97%,#1e5799)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #7db9e8 0%,#1e5799 97%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #7db9e8 0%,#1e5799 97%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #7db9e8 0%,#1e5799 97%); /* IE10+ */
background: linear-gradient(to bottom, #7db9e8 0%,#1e5799 97%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#7db9e8', endColorstr='#1e5799',GradientType=0 ); /* IE6-9 */
margin-top: -25px;
}
.submain:before{
content: '';
position: absolute;
bottom: 100%;
left: 0px;
height: 1px;
width: auto;
border-right: 300px solid #7CB7E7;
border-top: 25px solid transparent;
}
Is it real to make such border through css?
I thought about
border: 3px solid white;
border-top: none;
and pseudo-element with gradient, but its not exactly the same.
You can do this by adding a pseudo-element with a gradient. transparent -> white -> transparent.
FIDDLE
CSS
div
{
width: 600px;
height: 200px;
border: 5px solid black;
border-radius: 20px;
position: relative;
margin: 50px;
}
div:before
{
content: '';
position: absolute;
top:-5px;
left:0;right:0;
margin:auto;
height: 5px;
width: 80%;
background: -moz-linear-gradient(left, rgba(255,255,255,0) 0%, rgba(255,255,255,0) 1%, rgba(255,255,255,1) 17%, rgba(255,255,255,1) 85%, rgba(255,255,255,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,0)), color-stop(1%,rgba(255,255,255,0)), color-stop(17%,rgba(255,255,255,1)), color-stop(85%,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,0) 1%,rgba(255,255,255,1) 17%,rgba(255,255,255,1) 85%,rgba(255,255,255,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,0) 1%,rgba(255,255,255,1) 17%,rgba(255,255,255,1) 85%,rgba(255,255,255,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,0) 1%,rgba(255,255,255,1) 17%,rgba(255,255,255,1) 85%,rgba(255,255,255,0) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(255,255,255,0) 0%,rgba(255,255,255,0) 1%,rgba(255,255,255,1) 17%,rgba(255,255,255,1) 85%,rgba(255,255,255,0) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#00ffffff',GradientType=1 ); /* IE6-9 */
}
[Update: this can be done with a radial gradient, but Im no longer in front of my computer.]
I'm not sure that there's a border gradient (yet anyway), but I built something with nested s for you. Just an idea. It's just missing the solid white across the bottom. Hope it's helpful.
jsfiddle: http://jsfiddle.net/itsmikem/HfCT3/
css:
div {
position:relative;
}
#outer {
background: #cccc00;
width:200px;
padding:10px;
}
#mid {
border-radius:10px;
background: #ffffff;
background: -webkit-linear-gradient(left, #ffffff 0%,#cccc00 50%,#ffffff 100%);
background: linear-gradient(to right, #ffffff 0%,#cccc00 50%,#ffffff 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ffffff',GradientType=1 );
padding:3px;
}
#inner {
/*width:100%;
height:100%;*/
background:#cccc00;
border-radius:10px;
padding:10px;
}
html:
<div id="outer">
<div id="mid">
<div id="inner">stuff
</div>
</div>
</div>
How could one go about dynamically generating a shape like this in CSS3:
Ignore the borders, as the important aspects are:
- The gradient in the arrow body, and that the gradient lasts from the tip to the end of the arrow.
- The length of the square part will vary.
I tried the regular :after method of adding a triangle to the end of a div element, but I couldn’t get the gradient to span both the tip and the body properly.
Fiddle: http://jsfiddle.net/rtuY9/8/
You can try something like this - DEMO
div {
width: 50px;
height: 100px;
position: relative;
margin: 100px;
background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 100%);
background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 100%);
}
div:after {
z-index: -1;
content: "";
display: block;
position: absolute;
left: -125px;
top: -51px;
margin: 100px;
height: 100px;
width: 100px;
background: #c00;
-webkit-transform:rotate( -45deg );
-moz-transform:rotate( -45deg );
transform:rotate( -45deg );
background: -webkit-linear-gradient(45deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
background: -moz-linear-gradient(45deg, #1e5799 0%, #2989d8 50%, #ffffff 50%, #ffffff 100%);
}
I'm trying to get the background image to lay on top of the gradient background, do I have to create another div to do this?
#inner_bg {
width: 846px;
height: 646px;
margin: -1px 0 0 0;
background: url(../simg/inner_bg.gif) no-repeat 20px 140px;
background: #031f34;
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSI5JSIgc3RvcC1jb2xvcj0iIzAzMWYzNCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjQwJSIgc3RvcC1jb2xvcj0iIzAzNjY4ZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjcwJSIgc3RvcC1jb2xvcj0iIzA1YjdkMSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(left, #031f34 9%, #03668f 40%, #05b7d1 70%);
background: -webkit-gradient(linear, left top, right top, color-stop(9%,#031f34), color-stop(40%,#03668f), color-stop(70%,#05b7d1));
background: -webkit-linear-gradient(left, #031f34 9%,#03668f 40%,#05b7d1 70%);
background: -o-linear-gradient(left, #031f34 9%,#03668f 40%,#05b7d1 70%);
background: -ms-linear-gradient(left, #031f34 9%,#03668f 40%,#05b7d1 70%);
background: linear-gradient(to right, #031f34 9%,#03668f 40%,#05b7d1 70%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#031f34', endColorstr='#05b7d1',GradientType=1 );
float: left;
position: relative;
}
Yes you will need another element to work with (maybe a pseudo element like ::before), the backgrounds are replacing each other (when they are valid).
http://jsfiddle.net/fTpaz/2/
#inner_bg {
width: 846px;
height: 646px;
margin: -1px 0 0 0;
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSI5JSIgc3RvcC1jb2xvcj0iIzAzMWYzNCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjQwJSIgc3RvcC1jb2xvcj0iIzAzNjY4ZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjcwJSIgc3RvcC1jb2xvcj0iIzA1YjdkMSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(left, #031f34 9%, #03668f 40%, #05b7d1 70%);
background: -webkit-gradient(linear, left top, right top, color-stop(9%,#031f34), color-stop(40%,#03668f), color-stop(70%,#05b7d1));
background: -webkit-linear-gradient(left, #031f34 9%,#03668f 40%,#05b7d1 70%);
background: -o-linear-gradient(left, #031f34 9%,#03668f 40%,#05b7d1 70%);
background: -ms-linear-gradient(left, #031f34 9%,#03668f 40%,#05b7d1 70%);
background: linear-gradient(to right, #031f34 9%,#03668f 40%,#05b7d1 70%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#031f34', endColorstr='#05b7d1',GradientType=1 );
float: left;
position: relative;
}
#inner_bg::before{
content: ' ';
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
background: red;
opacity:0.5;
}
Create another divide. Position on top of the div with the gradient background. Add a z-index higher than that of the div with the gradient background.
I would like to create this shape using just css. I am pretty sure this can be done. But i am having trouble with gradients involved.
This shape will contain some text inside. Suggested html markup is:
<div class="container">
... more html contents...
</div>
A jsFiddle would be highly appreciated.
Thanks in advance.
Try this, http://jsfiddle.net/HshfF/1/
CSS: (From the fiddle in this comment)
.main {
background: -moz-linear-gradient(top, #ffffff 0%, #e8e8e8 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e8e8e8)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffff 0%,#e8e8e8 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffff 0%,#e8e8e8 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffff 0%,#e8e8e8 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffffff 0%,#e8e8e8 100%); /* W3C */
position: relative;
width: 150px;
height: 100px;
margin: 10px;
border: 1px solid #d0d0d0;
border-radius: 10px;
padding: 20px;
}
.main:before {
content: '';
display: block;
top: -1px;
right: -1px;
width: 20px;
height: 20px;
background: -moz-linear-gradient(top, #ffffff 0%, #e8e8e8 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e8e8e8)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffff 0%,#e8e8e8 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffff 0%,#e8e8e8 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffff 0%,#e8e8e8 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffffff 0%,#e8e8e8 100%); /* W3C */
position: absolute;
border-radius: 0 0 0 5px;
border-left: 1px solid #d0d0d0;
border-bottom: 1px solid #d0d0d0;
}
.main:after {
content: '';
display: block;
position: absolute;
top: -1px;
right: -1px;
border-top: 20px solid #fff;
border-left: 20px solid transparent;
}
Please Learn CSS3, Try Nicholas Gallagher tutorials, he has some of the best css3 tutorials:
one you looking for http://nicolasgallagher.com/pure-css-folded-corner-effect/demo/
The drop shadow and colors you looking for i think you need to do it yourself.
Nearly there with this: http://jsfiddle.net/Grezzo/52zG7/
You only need one div (thanks to pseudo element), but I haven't "cut" the corner yet.