Does anybody know how to do this? I need something like this:
I can find somebody doing it with .
hr {
border: 0;
height: 1px;
background: #333;
background: -webkit-gradient(linear, left top, right top, color-stop(0%,hsla(0,0%,0%,0)), color-stop(50%,hsla(0,0%,0%,.75)), color-stop(100%,hsla(0,0%,0%,0)));
background: -webkit-linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
background: -moz-linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
background: -ms-linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
background: -o-linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
background: linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
}
Link: http://jsfiddle.net/HdwKA/662/
But is there anyway I can do if with ::before or ::after?
If I want to add one more fade line on the left? What should I do?
Yes you can, by giving the element an absolute position, you can position the :before & :after pseudo element anywhere in respect to its element.
body {
background-color: black;
}
.hr {
background-color: green;
position: relative;
width: 100px;
height: 100px;
left: 150px;
top: 150px;
}
.hr:before {
content: '';
display: block;
position: absolute;
height: 50px;
width: 1px;
top: -50px;
left: 50%;
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&0+0,1+100 */
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 */
}
.hr:after {
content: '';
display: block;
position: absolute;
right: -50px;
top: 50%;
height: 1px;
width: 50px;
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&1+0,0+100 */
background: -moz-linear-gradient(left, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#00ffffff',GradientType=1 ); /* IE6-9 */
}
<div class="hr">
</div>
UPDATED
Here's an example using span
body {
background-color: black;
}
.hr {
background-color: green;
position: relative;
width: 100px;
height: 100px;
left: 150px;
top: 150px;
}
.top {
display: block;
position: absolute;
height: 50px;
width: 1px;
top: -50px;
left: 50%;
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&0+0,1+100 */
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 */
}
.bottom {
display: block;
position: absolute;
height: 50px;
width: 1px;
bottom: -50px;
left: 50%;
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&1+0,0+100;White+to+Transparent */
background: -moz-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#00ffffff',GradientType=0 ); /* IE6-9 */
}
.right {
display: block;
position: absolute;
right: -50px;
top: 50%;
height: 1px;
width: 50px;
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&1+0,0+100 */
background: -moz-linear-gradient(left, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#00ffffff',GradientType=1 ); /* IE6-9 */
}
.left {
display: block;
position: absolute;
left: -50px;
top: 50%;
height: 1px;
width: 50px;
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+100&0+0,1+100 */
background: -moz-linear-gradient(left, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, 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=1 ); /* IE6-9 */
}
<div class="hr">
<span class="left"></span>
<span class="right"></span>
<span class="top"></span>
<span class="bottom"></span>
</div>
that works with a pseudo selector.
I added you a solution to a fiddle based on a DIV element (but could be any other valid CSS selector):
http://codepen.io/marcbaur/pen/ZOxaxE/
div::after {
display: block;
width: 100%;
content: '';
border: 0;
height: 1px;
background: #333;
background: -webkit-gradient(linear, left top, right top, color-stop(0%,hsla(0,0%,0%,0)), color-stop(50%,hsla(0,0%,0%,.75)), color-stop(100%,hsla(0,0%,0%,0)));
background: -webkit-linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
background: -moz-linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
background: -ms-linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
background: -o-linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
background: linear-gradient(left, hsla(0,0%,0%,0) 0%, hsla(0,0%,0%,.75) 50%, hsla(0,0%,0%,0) 100%);
you just have to make sure that you define content, display and width properties.
Related
I'm working on an HTML/CSS chart that displays a series of financial groupings and visually shows how that money is distributed between companies. I've noticed that when the company names are long enough to take up multiple lines, its containing div drops down a bit.
I have the following fiddle: https://jsfiddle.net/s1pxkj7q/1/
Why are those divs getting pushed down and how do I correct it?
Thanks!
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.428571429;
color: #333333;
background-color: #ffffff;
}
#layers {
width: 1000px;
height: 400px;
margin: 0 auto;
}
#layer-headings {
width: 1000px;
margin: 0 auto;
}
#layer-headings h3 {
width: 50%;
text-align: center;
float: left;
font-size: 14px;
font-weight: bold;
margin-bottom: 50px;
}
#consumed {
width: 50%;
height: 100%;
outline: 1px solid #999;
display: inline-block;
margin: 0;
vertical-align: top;
}
#available {
width: 50%;
height: 100%;
display: inline-block;
margin: 0;
}
#layers h3 {
text-align: center;
font-size: 14px;
font-weight: bold;
margin: 0;
padding: 10px 0;
}
#layers .graph {
height: 100%;
width: 100%;
border-bottom: 1px solid #999;
}
#layers h4 {
font-size: 12px;
text-align: center;
}
#layers .graph-box {
margin-left: 5%;
width: 75%;
height: 100%;
float: left;
outline: 1px solid #555;
}
#layers .graph-box h4 {
font-weight: bold;
display: block;
margin: 0 auto;
}
#layers .graph-label {
margin-right: 5%;
padding-left: 10px;
width: 15%;
height: 100%;
vertical-align: top;
display: flex;
align-items: center;
}
#layers .graph-label h3 {
margin: 0;
padding: 0;
}
#layers .graph-col {
height: 100%;
display: inline-flex;
align-items: center;
outline: 1px solid #555;
}
#layers .graph-label.pdf {
display: inline-block;
}
#layers .graph-col.pdf {
display: inline-block;
}
.blue-grad {
background: #3085dd;
/* Old browsers */
background: -moz-linear-gradient(left, #3085dd 0%, #60abf8 50%, #3085dd 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, from(#3085dd), color-stop(0.5, #60abf8), to(#3085dd));
/* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(left, #3085dd 0%, #60abf8 50%, #3085dd 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #3085dd 0%, #60abf8 50%, #3085dd 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#3085dd', endColorstr='#3085dd', GradientType=1);
/* IE6-9 */
}
.red-grad {
background: #e54b29;
/* Old browsers */
background: -moz-linear-gradient(left, #e54b29 0%, #fc8364 50%, #e54b29 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, from(#e54b29), color-stop(0.5, #fc8364), to(#e54b29));
/* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(left, #e54b29 0%, #fc8364 50%, #e54b29 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #e54b29 0%, #fc8364 50%, #e54b29 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#e54b29', endColorstr='#e54b29', GradientType=1);
/* IE6-9 */
}
.yellow-grad {
background: #e2dd31;
/* Old browsers */
background: -moz-linear-gradient(left, #e2dd31 0%, #fffa7a 50%, #e2dd31 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, from(#e2dd31), color-stop(0.5, #fffa7a), to(#e2dd31));
/* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(left, #e2dd31 0%, #fffa7a 50%, #e2dd31 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #e2dd31 0%, #fffa7a 50%, #e2dd31 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#e2dd31', endColorstr='#e2dd31', GradientType=1);
/* IE6-9 */
}
.green-grad {
background: #3bdb30;
/* Old browsers */
background: -moz-linear-gradient(left, #3bdb30 0%, #8cf984 50%, #3bdb30 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, from(#3bdb30), color-stop(0.5, #8cf984), to(#3bdb30));
/* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(left, #3bdb30 0%, #8cf984 50%, #3bdb30 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #3bdb30 0%, #8cf984 50%, #3bdb30 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#3bdb30', endColorstr='#3bdb30', GradientType=1);
/* IE6-9 */
}
.purple-grad {
background: #894bed;
/* Old browsers */
background: -moz-linear-gradient(left, #894bed 0%, #be99ff 50%, #894bed 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, from(#894bed), color-stop(0.5, #be99ff), to(#894bed));
/* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(left, #894bed 0%, #be99ff 50%, #894bed 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #894bed 0%, #be99ff 50%, #894bed 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#894bed', endColorstr='#894bed', GradientType=1);
/* IE6-9 */
}
.orange-grad {
background: #d89531;
/* Old browsers */
background: -moz-linear-gradient(left, #d89531 0%, #fcce99 50%, #d89531 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, from(#d89531), color-stop(0.5, #fcce99), to(#d89531));
/* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(left, #d89531 0%, #fcce99 50%, #d89531 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #d89531 0%, #fcce99 50%, #d89531 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#d89531', endColorstr='#d89531', GradientType=1);
/* IE6-9 */
}
.cyan-grad {
background: #49e5e0;
/* Old browsers */
background: -moz-linear-gradient(left, #49e5e0 0%, #b8f9f5 50%, #49e5e0 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, from(#49e5e0), color-stop(0.5, #b8f9f5), to(#49e5e0));
/* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(left, #49e5e0 0%, #b8f9f5 50%, #49e5e0 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #49e5e0 0%, #b8f9f5 50%, #49e5e0 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#49e5e0', endColorstr='#49e5e0', GradientType=1);
/* IE6-9 */
}
.deepblue-grad {
background: #3b52d3;
/* Old browsers */
background: -moz-linear-gradient(left, #3b52d3 0%, #7692f7 50%, #3b52d3 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, from(#3b52d3), color-stop(0.5, #7692f7), to(#3b52d3));
/* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(left, #3b52d3 0%, #7692f7 50%, #3b52d3 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #3b52d3 0%, #7692f7 50%, #3b52d3 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#3b52d3', endColorstr='#3b52d3', GradientType=1);
/* IE6-9 */
}
.pink-grad {
background: #db3dce;
/* Old browsers */
background: -moz-linear-gradient(left, #db3dce 0%, #fc94f5 50%, #db3dce 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, from(#db3dce), color-stop(0.5, #fc94f5), to(#db3dce));
/* Safari 4-5, Chrome 1-9 */
background: -webkit-linear-gradient(left, #db3dce 0%, #fc94f5 50%, #db3dce 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right, #db3dce 0%, #fc94f5 50%, #db3dce 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#db3dce', endColorstr='#db3dce', GradientType=1);
/* IE6-9 */
}
#layers #consumed .graph {
padding-right: 5%;
position: relative;
}
#layers #consumed .graph-col {
vertical-align: bottom;
}
#layers #consumed .graph-label {
float: left;
margin-left: 5%;
}
#layers #consumed .graph-row {
position: absolute;
bottom: 0;
width: 100%;
padding-right: 5%;
}
#layers #consumed .graph-box {
margin-left: 0;
}
<div id="layers">
<div id="available">
<div class="graph">
<div class="graph-row" style="height:20%;">
<div class="graph-box red-grad" style="outline:1px solid #555;">
<div class="graph-col" style="width:40%;">
<h4>40%<br>Short</h4>
</div>
<div class="graph-col" style="width:20%;">
<h4>20%<br>This is a long one</h4>
</div>
<div class="graph-col" style="width:30%;">
<h4>30%<br>Short</h4>
</div>
<div class="graph-col" style="width:10%;">
<h4>10%<br>Short</h4>
</div>
</div>
<div class="graph-label">
<h3>$750,000</h3>
</div>
</div>
<div class="graph-row" style="height:27%;">
<div class="graph-box cyan-grad">
<div class="graph-col" style="width:20%;">
<h4>20%<br>Short</h4>
</div>
<div class="graph-col" style="width:40%;">
<h4>40%<br>Short</h4>
</div>
<div class="graph-col" style="width:15%;">
<h4>15%<br>Short</h4>
</div>
<div class="graph-col" style="width:10%;">
<h4>10%<br>Short</h4>
</div>
<div class="graph-col" style="width:15%;">
<h4>15%<br>Short</h4>
</div>
</div>
<div class="graph-label">
<h3>$1,000,000</h3>
</div>
</div>
<div class="graph-row" style="height:27%;">
<div class="graph-box yellow-grad">
<div class="graph-col" style="width:25%;">
<h4>25%<br>Short</h4>
</div>
<div class="graph-col" style="width:22%;">
<h4>22%<br>This is a long one</h4>
</div>
<div class="graph-col" style="width:18%;">
<h4>18%<br>Short</h4>
</div>
<div class="graph-col" style="width: 17%;">
<h4>17%<br>Short</h4>
</div>
<div class="graph-col" style="width:18%;">
<h4>18%<br>Short</h4>
</div>
</div>
<div class="graph-label">
<h3>$1,000,000</h3>
</div>
</div>
<div class="graph-row" style="height:14%;">
<div class="graph-box purple-grad">
<div class="graph-col" style="width:100%;">
<h4>100%<br>Short</h4>
</div>
</div>
<div class="graph-label">
<h3>$500,000</h3>
</div>
</div>
<div class="graph-row" style="height:12%;">
<div class="graph-box orange-grad">
<div class="graph-col" style="width:100%;">
<h4>100%<br>Short</h4>
</div>
</div>
<div class="graph-label">
<h3>$400,000</h3>
</div>
</div>
</div>
</div>
</div>
The problem is baseline alignment due to the vertical-align property.
The vertical-align property applies to inline-level and table-cell elements (source).
Since you're dealing with inline-level containers (display: inline-flex), vertical-align is being applied and its default value is baseline.
Simply override that with vertical-align: top on your containers.
#layers .graph-col {
height: 100%;
display: inline-flex;
align-items: center;
outline: 1px solid #555;
vertical-align: top; /* NEW */
}
I am generating a gradient on the page. How can I overlay an image in the center of this ribbon? I need to center the image and I cant seem to figure out how to make this work. I am using bootstrap and the page is responsive. So it needs to stay together when the page gets smaller. Any help is appreciated!
Desired Result:
#ribbon-background {
background: #ed1c24; /* Old browsers */
background: -moz-linear-gradient(left, #ed1c24 0%, #600000 50%, #ed1c24 100%); /* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#ed1c24), color-stop(50%,#600000), color-stop(100%,#ed1c24)); /* Chrome4-9,Safari4-5 */
background: -webkit-linear-gradient(left, #ed1c24 0%,#600000 50%,#ed1c24 100%); /* Chrome10-25,Safari5.1-6 */
background: -o-linear-gradient(left, #ed1c24 0%,#600000 50%,#ed1c24 100%); /* Opera 11.10-11.50 */
background: -ms-linear-gradient(left, #ed1c24 0%,#600000 50%,#ed1c24 100%); /* IE10 preview */
background: linear-gradient(to right, #ed1c24 0%,#600000 50%,#ed1c24 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ed1c24', endColorstr='#ed1c24',GradientType=1 ); /* IE6-9 */
border-top: 3px solid #000;
border-bottom: 3px solid #000;
box-shadow: 0 7px 0 #FFF inset,
0 -7px 0 #FFF inset;
height: 65px;
margin: 0 auto;
width: 100%;
z-index: 99;
}
<div id="ribbon-background"></div>
One way to do that is to give the ribbon a position: relative; and add the follow style to a child <img>:
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
Demo:
#ribbon-background {
background: #ed1c24;
/* Old browsers */
background: -moz-linear-gradient(left, #ed1c24 0%, #600000 50%, #ed1c24 100%);
/* FF3.6-15 */
background: -webkit-gradient(linear, left top, right top, color-stop(0%, #ed1c24), color-stop(50%, #600000), color-stop(100%, #ed1c24));
/* Chrome4-9,Safari4-5 */
background: -webkit-linear-gradient(left, #ed1c24 0%, #600000 50%, #ed1c24 100%);
/* Chrome10-25,Safari5.1-6 */
background: -o-linear-gradient(left, #ed1c24 0%, #600000 50%, #ed1c24 100%);
/* Opera 11.10-11.50 */
background: -ms-linear-gradient(left, #ed1c24 0%, #600000 50%, #ed1c24 100%);
/* IE10 preview */
background: linear-gradient(to right, #ed1c24 0%, #600000 50%, #ed1c24 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ed1c24', endColorstr='#ed1c24', GradientType=1);
/* IE6-9 */
border-top: 3px solid #000;
border-bottom: 3px solid #000;
box-shadow: 0 7px 0 #FFF inset, 0 -7px 0 #FFF inset;
height: 65px;
margin: 0 auto;
width: 100%;
z-index: 99;
position: relative;
}
#ribbon-overlay-img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div id="ribbon-background">
<img id="ribbon-overlay-img" src="http://www.iconsdb.com/icons/preview/orange/stackoverflow-4-xxl.png">
</div>
Is it possible by using styles to create an DIV like this?
I mean the structure of the plinth. A similar 3D effect
It is kind of possible. You can use background: linear-gradient() for the colors and multiple div's with border-radius for the shape and different heights and widths, e.g.:
.wrapper {
width: 300px;
}
.layer1 {
height: 10px;
width: 300px;
float: right;
border-bottom-left-radius: 8px;
background: #eeeeee;
/* Old browsers */
background: -moz-linear-gradient(top, #eeeeee 0%, #cccccc 100%);
/* FF3.6-15 */
background: -webkit-linear-gradient(top, #eeeeee 0%, #cccccc 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #eeeeee 0%, #cccccc 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#cccccc', GradientType=0);
/* IE6-9 */
}
.layer2 {
height: 30px;
width: 280px;
float: right;
border-bottom-left-radius: 25px;
background: #b5b5b5;
/* Old browsers */
background: -moz-linear-gradient(top, #b5b5b5 0%, #eeeeee 48%, #cccccc 100%);
/* FF3.6-15 */
background: -webkit-linear-gradient(top, #b5b5b5 0%, #eeeeee 48%, #cccccc 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #b5b5b5 0%, #eeeeee 48%, #cccccc 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#b5b5b5', endColorstr='#cccccc', GradientType=0);
/* IE6-9 */
}
.layer3 {
height: 20px;
width: 230px;
float: right;
border-bottom-left-radius: 15px;
background: #eeeeee;
/* Old browsers */
background: -moz-linear-gradient(top, #eeeeee 0%, #cccccc 100%);
/* FF3.6-15 */
background: -webkit-linear-gradient(top, #eeeeee 0%, #cccccc 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #eeeeee 0%, #cccccc 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#cccccc', GradientType=0);
/* IE6-9 */
}
<div class="wrapper">
<div class="layer1"></div>
<div class="layer2"></div>
<div class="layer3"></div>
</div>
Just play around with the properties a little bit and I'm sure you will get nice results. The above is just a quick ugly example...
Limitations: With this approach it's only possible to build convex curves.
I've some scenario where I should use multiple background color to one div. It's better for me rather than using background images or additional div. But, I can't find easier way to use it by CSS. So, I need help about some scenario. Please, see the image:
(1) I want to build "A". for that I wrote:
div.A { background: linear-gradient(to right, #9c9e9f, #f6f6f6); }
But, after writing that code, it'll like "B". But, I want exactly like "A". So, by css/css3 how can I do it(without adding more divs)?
(2) Is it possible to make one portion smaller than other portion? For example, at "C", blue color is smaller(at height) than the other portion. How, can I apply multiple background color to one div with making one portion smaller like "C"(without adding additional divs to "C")?
Update:
After #Mohammad's answer, I've tried with that way. But, for "C" scenario, I can't decrease the height of blue portion. Can you please, tell me how can I do it?
jsfiddle.net/mFjQ6
The A div can actually be made without :before or :after selector but using linear gradient as your first try. The only difference is that you must specify 4 positions. Dark grey from 0 to 50% and ligth grey from 50% to 100% like this:
background: linear-gradient(to right, #9c9e9f 0%,#9c9e9f 50%,#f6f6f6 50%,#f6f6f6 100%);
As you know, B div is made from a linear gradient having 2 positions like this:
background: linear-gradient(to right, #9c9e9f 0%,#f6f6f6 100%);
For the C div, i use the same kind of gradient as div A ike this:
background: linear-gradient(to right, #9c9e9f 0%,#9c9e9f 50%,#33ccff 50%,#33ccff 100%);
But this time i used the :after selector with a white background like if the second part of your div was smaller. * Please note that I added a better alternative below.
Check this jsfiddle or the snippet below for complete cross-browser code.
div{
position:relative;
width:80%;
height:100px;
color:red;
text-align:center;
line-height:100px;
margin-bottom:10px;
}
.a{
background: #9c9e9f; /* Old browsers */
background: -moz-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, #f6f6f6 50%, #f6f6f6 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#9c9e9f), color-stop(50%,#9c9e9f), color-stop(50%,#f6f6f6), color-stop(100%,#f6f6f6)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #9c9e9f 0%,#9c9e9f 50%,#f6f6f6 50%,#f6f6f6 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #9c9e9f 0%,#9c9e9f 50%,#f6f6f6 50%,#f6f6f6 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, #9c9e9f 0%,#9c9e9f 50%,#f6f6f6 50%,#f6f6f6 100%); /* IE10+ */
background: linear-gradient(to right, #9c9e9f 0%,#9c9e9f 50%,#f6f6f6 50%,#f6f6f6 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9c9e9f', endColorstr='#f6f6f6',GradientType=1 ); /* IE6-9 */
}
.b{
background: #9c9e9f; /* Old browsers */
background: -moz-linear-gradient(left, #9c9e9f 0%, #f6f6f6 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#9c9e9f), color-stop(100%,#f6f6f6)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #9c9e9f 0%,#f6f6f6 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #9c9e9f 0%,#f6f6f6 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, #9c9e9f 0%,#f6f6f6 100%); /* IE10+ */
background: linear-gradient(to right, #9c9e9f 0%,#f6f6f6 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9c9e9f', endColorstr='#f6f6f6',GradientType=1 ); /* IE6-9 */
}
.c{
background: #9c9e9f; /* Old browsers */
background: -moz-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, #33ccff 50%, #33ccff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#9c9e9f), color-stop(50%,#9c9e9f), color-stop(50%,#33ccff), color-stop(100%,#33ccff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #9c9e9f 0%,#9c9e9f 50%,#33ccff 50%,#33ccff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #9c9e9f 0%,#9c9e9f 50%,#33ccff 50%,#33ccff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, #9c9e9f 0%,#9c9e9f 50%,#33ccff 50%,#33ccff 100%); /* IE10+ */
background: linear-gradient(to right, #9c9e9f 0%,#9c9e9f 50%,#33ccff 50%,#33ccff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9c9e9f', endColorstr='#33ccff',GradientType=1 ); /* IE6-9 */
}
.c:after{
content:"";
position:absolute;
right:0;
bottom:0;
width:50%;
height:20%;
background-color:white;
}
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
There is also an alternative for the C div without using a white background to hide the a part of the second section.
Instead, we make the second part transparent and we use the :after selector to act as a colored background with the desired position and size.
See this jsfiddle or the snippet below for this updated solution.
div {
position: relative;
width: 80%;
height: 100px;
color: red;
text-align: center;
line-height: 100px;
margin-bottom: 10px;
}
.a {
background: #9c9e9f;
/* Old browsers */
background: -moz-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, #f6f6f6 50%, #f6f6f6 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%, #9c9e9f), color-stop(50%, #9c9e9f), color-stop(50%, #f6f6f6), color-stop(100%, #f6f6f6));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, #f6f6f6 50%, #f6f6f6 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, #f6f6f6 50%, #f6f6f6 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, #f6f6f6 50%, #f6f6f6 100%);
/* IE10+ */
background: linear-gradient(to right, #9c9e9f 0%, #9c9e9f 50%, #f6f6f6 50%, #f6f6f6 100%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9c9e9f', endColorstr='#f6f6f6', GradientType=1);
/* IE6-9 */
}
.b {
background: #9c9e9f;
/* Old browsers */
background: -moz-linear-gradient(left, #9c9e9f 0%, #f6f6f6 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%, #9c9e9f), color-stop(100%, #f6f6f6));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #9c9e9f 0%, #f6f6f6 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #9c9e9f 0%, #f6f6f6 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(left, #9c9e9f 0%, #f6f6f6 100%);
/* IE10+ */
background: linear-gradient(to right, #9c9e9f 0%, #f6f6f6 100%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9c9e9f', endColorstr='#f6f6f6', GradientType=1);
/* IE6-9 */
}
.c {
background: #9c9e9f;
/* Old browsers */
background: -moz-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0) 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%, #9c9e9f), color-stop(50%, #9c9e9f), color-stop(50%, rgba(0, 0, 0, 0)), color-stop(100%, rgba(0, 0, 0, 0)));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0) 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0) 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(left, #9c9e9f 0%, #9c9e9f 50%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0) 100%);
/* IE10+ */
background: linear-gradient(to right, #9c9e9f 0%, #9c9e9f 50%, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0) 100%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9c9e9f', endColorstr='#ffffff00', GradientType=1);
/* IE6-9 */
}
.c:after {
content: "";
position: absolute;
right: 0;
top: 0;
width: 50%;
height: 80%;
background-color: #33ccff;
z-index: -1
}
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
You could apply both background-color and border to make it look like 2 colors.
div.A { width: 50px; background-color: #9c9e9f; border-right: 50px solid #f6f6f6; }
The border should have the same size as the width.
Sorry for misunderstanding, from what I understood you want your DIV to have three different colors with different heights. This is the output of my code:
,
If this is what you want try this code:
div {
height: 100px;
width:400px;
position: relative;
}
.c {
background: blue; /* Old browsers */
}
.c:after{
content: '';
position: absolute;
width:20%;
left:0;
height:110%;
background: yellow;
}
.c:before{
content: '';
position: absolute;
width:40%;
left:60%;
height:140%;
background: green;
}
<div class="c"></div>
it is compatible with all the browsers, change values to fit your application
background: #fdfdfd;
background: -moz-linear-gradient(top, #fdfdfd 0%, #f6f6f6 60%, #f2f2f2 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fdfdfd), color-stop(60%,#f6f6f6), color-stop(100%,#f2f2f2));
background: -webkit-linear-gradient(top, #fdfdfd 0%,#f6f6f6 60%,#f2f2f2 100%);
background: -o-linear-gradient(top, #fdfdfd 0%,#f6f6f6 60%,#f2f2f2 100%);
background: -ms-linear-gradient(top, #fdfdfd 0%,#f6f6f6 60%,#f2f2f2 100%);
background: linear-gradient(to bottom, #fdfdfd 0%,#f6f6f6 60%,#f2f2f2 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fdfdfd', endColorstr='#f2f2f2',GradientType=0
With :after and :before you can do that.
HTML:
<div class="a"> </div>
<div class="b"> </div>
<div class="c"> </div>
CSS:
div {
height: 100px;
position: relative;
}
.a {
background: #9C9E9F;
}
.b {
background: linear-gradient(to right, #9c9e9f, #f6f6f6);
}
.a:after, .c:before, .c:after {
content: '';
width: 50%;
height: 100%;
top: 0;
right: 0;
display: block;
position: absolute;
}
.a:after {
background: #f6f6f6;
}
.c:before {
background: #9c9e9f;
left: 0;
}
.c:after {
background: #33CCFF;
right: 0;
height: 80%;
}
And a demo.
You can create something like c using CSS multiple-backgrounds.
div {
background: linear-gradient(red, red),
linear-gradient(blue, blue),
linear-gradient(green, green);
background-size: 30% 50%,
30% 60%,
40% 80%;
background-position: 0% top,
calc(30% * 100 / (100 - 30)) top,
calc(60% * 100 / (100 - 40)) top;
background-repeat: no-repeat;
}
Note, you still have to use linear-gradients for background types, because CSS will not allow you to control the background-size of a single color layer. So here we just make a single-color gradient. Then you can control the size/position of each of those blocks of color independently. You also have to make sure they don't repeat, or they'll just expand and cover the whole image.
The trickiest part here is background-position. A background-position of 0% puts your element's left edge at the left. 100% puts its right edge at the right. 50% centers is middle.
For a fun bit of math to solve that, you can guess the transform is probably linear, and just solve two little slope-intercept equations.
// (at 0%, the div's left edge is 0% from the left)
0 = m * 0 + b
// (at 100%, the div's right edge is 100% - width% from the left)
100 = m * (100 - width) + b
b = 0, m = 100 / (100 - width)
so to position our 40% wide div 60% from the left, we put it at 60% * 100 / (100 - 40) (or use css-calc).
background: linear-gradient(152deg , #0A64B1 60%,#0A64B1 33%,#2C3E52 45%,#2C3E52 156%);
You can do this way:-
In CSS file:-
<style>
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
.container {
display: flex;
}
.split {
height: 100vh;
width: 50%;
top: 0;
}
.left {
background-color: lightblue;
left: 0;
}
.left h1 {
text-align: center;
margin-top: 20%;
font-size: 90px;
}
.right {
background-color: lightsalmon;
right: 0;
}
.footer {
background-color: black;
color: white;
font-size: 13px;
padding: 1px;
}
</style>
And in body:-
<body>
<div class="container">
<div class="split left">
<h1>Welcome<br>to<br>website</h1>
</div>
<div class="split right">
<h2>welcome<br>to<br>website</h2>
</div>
</div>
<div class="footer">
<h3>copyright ©</h3>
</div>
</body>
I have edited some cool scrollbars. I needed text to be in the middle, so it is like a frame...like you see when you accept someones terms of service and stuff. I have tried to add text, but i can not seem to get it to work? http://jsfiddle.net/Hunter4854/RHMCm/ Please do not down vote if you have a question, just add a comment, and i will answer :)
<head>
<meta content="en-us" http-equiv="Content-Language">
<style>body {
top: 0;
left: 0;
bottom: 0;
right: 0;
background: green;
}
.a::-webkit-scrollbar {
width: 15px;
height: 15px;
}
.a::-webkit-scrollbar:vertical {
background: -webkit-linear-gradient(left, #525252 0%,#202020 50%,#020202 50%,#101010 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(left, #525252 0%,#202020 50%,#020202 50%,#101010 100%); /* W3C */
}
.a::-webkit-scrollbar:horizontal {
background: -webkit-linear-gradient(top, #525252 0%,#202020 50%,#020202 50%,#101010 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(top, #525252 0%,#202020 50%,#020202 50%,#101010 100%); /* W3C */
}
.a::-webkit-scrollbar-track:vertical {
background: -webkit-linear-gradient(left, #1d1d1d 0%,#1b1b1b 50%,#171717 50%,#1d1d1d 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(left, #1d1d1d 0%,#1b1b1b 50%,#171717 50%,#1d1d1d 100%); /* W3C */
border-radius: 15px;
}
.a::-webkit-scrollbar-track:horizontal {
background: -webkit-linear-gradient(top, #1d1d1d 0%,#1b1b1b 50%,#171717 50%,#1d1d1d 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(top, #1d1d1d 0%,#1b1b1b 50%,#171717 50%,#1d1d1d 100%); /* W3C */
border-radius: 15px;
}
.a::-webkit-scrollbar-thumb {
border-radius: 15px;
border: 1px solid black;
}
.a::-webkit-scrollbar-thumb:vertical {
background: -webkit-linear-gradient(left, #878787 0%,#474747 50%,#282828 50%,#4a4a4a 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(left, #878787 0%,#474747 50%,#282828 50%,#4a4a4a 100%); /* W3C */
}
.a::-webkit-scrollbar-thumb:horizontal {
background: -webkit-linear-gradient(top, #878787 0%,#474747 50%,#282828 50%,#4a4a4a 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(top, #878787 0%,#474747 50%,#282828 50%,#4a4a4a 100%); /* W3C */
}
.a::-webkit-scrollbar-thumb:hover {
}
.a::-webkit-scrollbar-corner {
background: black;
}
.a::-webkit-scrollbar-button:vertical {
background: -webkit-linear-gradient(left, #525252 0%,#202020 50%,#020202 50%,#101010 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(left, #525252 0%,#202020 50%,#020202 50%,#101010 100%); /* W3C */
}
.a::-webkit-scrollbar-button:horizontal {
background: -webkit-linear-gradient(top, #525252 0%,#202020 50%,#020202 50%,#101010 100%); /* Chrome10+,Safari5.1+ */
background: linear-gradient(top, #525252 0%,#202020 50%,#020202 50%,#101010 100%); /* W3C */
}
</style>
</head>
<div class="a" style="position:absolute;width:200px;height:200px;background:white;overflow-y:scroll">
</div>
See it here http://jsfiddle.net/3uTjv/