Related
So, I'm trying to make a div vertically centered using CSS position and transform method but apparently it is making the div slightly horizontally off centered. here's my code:
HTML:
<div class="row container-fluid top_header">
<div class="col-12 container-xl">
<div class="top_header_texts"></div>
</div>
</div>
CSS:
.top_header {
box-sizing: border-box;
background-image: radial-gradient(circle at 19% 90%, rgba(190, 190, 190,0.04) 0%, rgba(190, 190, 190,0.04) 17%,transparent 17%, transparent 100%),radial-gradient(circle at 73% 2%, rgba(78, 78, 78,0.04) 0%, rgba(78, 78, 78,0.04) 94%,transparent 94%, transparent 100%),radial-gradient(circle at 45% 2%, rgba(18, 18, 18,0.04) 0%, rgba(18, 18, 18,0.04) 55%,transparent 55%, transparent 100%),radial-gradient(circle at 76% 60%, rgba(110, 110, 110,0.04) 0%, rgba(110, 110, 110,0.04) 34%,transparent 34%, transparent 100%),radial-gradient(circle at 68% 56%, rgba(246, 246, 246,0.04) 0%, rgba(246, 246, 246,0.04) 16%,transparent 16%, transparent 100%),radial-gradient(circle at 71% 42%, rgba(156, 156, 156,0.04) 0%, rgba(156, 156, 156,0.04) 47%,transparent 47%, transparent 100%),radial-gradient(circle at 46% 82%, rgba(247, 247, 247,0.04) 0%, rgba(247, 247, 247,0.04) 39%,transparent 39%, transparent 100%),radial-gradient(circle at 50% 47%, rgba(209, 209, 209,0.04) 0%, rgba(209, 209, 209,0.04) 45%,transparent 45%, transparent 100%),linear-gradient(90deg, rgb(84, 36, 210),rgb(44, 27, 154));
background-size: cover;
background-repeat: no-repeat;
margin: 0 0 0 0;
width: 100%;
height: 95vh;
position: relative;
}
.top_header_texts {
display: block;
margin: 0 auto;
color: White;
font-weight: bold;
font-size: 60px;
position: absolute;
top:50%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
width: 100%;
background-color: red;
}
Result:
As you can see there's a little gap in the left but nothing in the right, this is nothing major but bothering me and couldn't get anything to sort this out
Assuming you are using the latest version of bootstrap. (4.1.1)
The .container-fluid and .col-12 have padding attributes, and you can try to overwrite it by .p-0 class
<div class="row container-fluid top_header p-0">
<div class="col-12 container-xl p-0">
<div class="top_header_texts"></div>
</div>
</div>
Online Verification
container-fluid and container-xl classes of bootstrap brings padding-left:15px. try setting it to zero.
HTML:
<div class="row container-fluid top_header paddingLeft_0">
<div class="col-12 container-xl paddingLeft_0">
<div class="top_header_texts"></div>
</div>
</div>
CSS:
div.paddingLeft_0 {
padding-left:0;
}
Just a text-align: center fixes the problem, as you see:
.top_header {
box-sizing: border-box;
background-image: radial-gradient(circle at 19% 90%, rgba(190, 190, 190,0.04) 0%, rgba(190, 190, 190,0.04) 17%,transparent 17%, transparent 100%),radial-gradient(circle at 73% 2%, rgba(78, 78, 78,0.04) 0%, rgba(78, 78, 78,0.04) 94%,transparent 94%, transparent 100%),radial-gradient(circle at 45% 2%, rgba(18, 18, 18,0.04) 0%, rgba(18, 18, 18,0.04) 55%,transparent 55%, transparent 100%),radial-gradient(circle at 76% 60%, rgba(110, 110, 110,0.04) 0%, rgba(110, 110, 110,0.04) 34%,transparent 34%, transparent 100%),radial-gradient(circle at 68% 56%, rgba(246, 246, 246,0.04) 0%, rgba(246, 246, 246,0.04) 16%,transparent 16%, transparent 100%),radial-gradient(circle at 71% 42%, rgba(156, 156, 156,0.04) 0%, rgba(156, 156, 156,0.04) 47%,transparent 47%, transparent 100%),radial-gradient(circle at 46% 82%, rgba(247, 247, 247,0.04) 0%, rgba(247, 247, 247,0.04) 39%,transparent 39%, transparent 100%),radial-gradient(circle at 50% 47%, rgba(209, 209, 209,0.04) 0%, rgba(209, 209, 209,0.04) 45%,transparent 45%, transparent 100%),linear-gradient(90deg, rgb(84, 36, 210),rgb(44, 27, 154));
background-size: cover;
background-repeat: no-repeat;
margin: 0 0 0 0;
flex: 0 0 100%;
height: 95vh;
position: relative;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.top_header .col-12 {
width: 100%;
}
.top_header_texts {
margin: 0 auto;
color: White;
font-weight: bold;
font-size: 60px;
background-color: red;
text-align: center
}
<div class="row container-fluid top_header">
<div class="col-12 container-xl">
<div class="top_header_texts">text</div>
</div>
</div>
use .text-center or .mx-auto to keep content on the center
I'm trying to understand how a linear gradient with only one color specified is producing a background with two different colors.
.book-bg {
height: 100px;
width: 100%;
background: #24ab9d
linear-gradient(
to bottom,
#238d82 16px,
rgba(35, 141, 130, 0) 16px,
rgba(35, 141, 130, 0) 100%
)
}
<div class="book-bg"></div>
I would expect this linear gradient to produce a background with only #238d82. The rgba value (rgba(35, 141, 130, 0)) converts to the same hex code so shouldn't this div just be one color? What is causing the dark strip at the top?
What you are seeing is the #24ab9d that you defined to be the background-color layer. Your code is equialent to this one:
.book-bg {
height: 100px;
width: 100%;
background:
linear-gradient( to bottom, #238d82 16px, rgba(35, 141, 130, 0) 16px, rgba(35, 141, 130, 0) 100%);
background-color: #24ab9d;
}
<div class="book-bg"></div>
Or this one since you are considering transparent color:
.book-bg {
height: 100px;
width: 100%;
background:
linear-gradient( to bottom, #238d82 16px, transparent 16px);
background-color: #24ab9d;
}
<div class="book-bg"></div>
Also the same as:
.book-bg {
height: 100px;
width: 100%;
background:
linear-gradient( to bottom, #238d82 16px, #24ab9d 16px);
}
<div class="book-bg"></div>
.book-bg {
height: 100px;
width: 100%;
background: #24ab9d
linear-gradient(
to bottom,
#238d82 0px,
rgba(35, 141, 130, 0) 16px,
rgba(35, 141, 130, 0) 100%
);
}
Start colour of a linear gradient function is starting from 16px because of which you are seeing a dark strip at the top.
Is there any way that I can have 4 different colours on one side of a border in CSS? I currently have
#header
{
border-color:#88a9eb;
}
I want to have a border of 4 solid colours, with a 25% split on each, Is this something that is possible?
I want to make a solid version of this without the white bits in between.
You can use the border-image property to create a gradient border with 4 colors. Normally gradients move gradually from one color to another and it produces a blur like effect but setting the color-stops (the percentage values) such that the end-point of one color is same as the starting point of the next color makes the colors come to a hard stop and thus end up producing block like effects.
The border can be set to the required side by changing the border-image-width and the direction of the gradient. For example, top & bottom borders would need the gradient to go from left to right while left & right borders would need the gradient to go from top to bottom.
The gradients use percentage values for the size (and color-stop) and hence they are responsive by default and can adapt automatically even if the container's dimensions change.
The only drawback to using border-image is the poor browser support for this property at present. IE10- do not support this property.
.bordered-top {
border-image: linear-gradient(to right, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
border-image-slice: 1;
border-image-width: 4px 0px 0px 0px;
}
.bordered-bottom {
border-image: linear-gradient(to right, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
border-image-slice: 1;
border-image-width: 0px 0px 4px 0px;
}
.bordered-left {
border-image: linear-gradient(to bottom, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
border-image-slice: 1;
border-image-width: 0px 0px 0px 4px;
}
.bordered-right {
border-image: linear-gradient(to bottom, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
border-image-slice: 1;
border-image-width: 0px 4px 0px 0px;
}
div {
height: 100px;
width: 300px;
padding: 10px;
background: beige;
margin: 10px;
}
<!-- library added only for old browser support -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class='bordered-top'>Border only on top</div>
<div class='bordered-bottom'>Border only on bottom</div>
<div class='bordered-left'>Border only on left</div>
<div class='bordered-right'>Border only on right</div>
For IE10+ support, you could mimic the same behavior by using gradients for the background-image property instead of border-image like in the below snippet.
Unlike with border-image, here the side on which the border is applied cannot be controlled using the border-image-width and we have to use background-position instead to position the image at the required position.
The background-size determines the thickness of the border. For top & bottom borders, the size in x-axis should be 100% and that in y-axis is the thickness of the border. For left & right borders, the size in y-axis should be 100% and that in x-axis is the thickness of the border.
.bordered-top {
background-image: linear-gradient(to right, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
background-size: 100% 4px;
background-repeat: no-repeat;
background-position: 0% 0%;
}
.bordered-bottom {
background-image: linear-gradient(to right, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
background-size: 100% 4px;
background-repeat: no-repeat;
background-position: 0% 100%;
}
.bordered-left {
background-image: linear-gradient(to bottom, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
background-size: 4px 100%;
background-repeat: no-repeat;
background-position: 0% 0%;
}
.bordered-right {
background-image: linear-gradient(to bottom, rgb(139, 191, 64) 25%, rgb(230, 27, 33) 25%, rgb(230, 27, 33) 50%, rgb(124, 196, 236) 50%, rgb(124, 196, 236) 75%, rgb(254, 181, 17) 75%);
background-size: 4px 100%;
background-repeat: no-repeat;
background-position: 100% 0%;
}
div {
height: 100px;
width: 300px;
padding: 10px;
background: beige;
margin: 10px;
}
<!-- library added only for old browser support -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class='bordered-top'>Border only on top</div>
<div class='bordered-bottom'>Border only on bottom</div>
<div class='bordered-left'>Border only on left</div>
<div class='bordered-right'>Border only on right</div>
You can use box-shadow and after psuedo-element to do this
What I did:
I first created an :after element on the bottom, then added box-shadows horizontally with different colors
If you want to change the strength of the border simply give more height to the :after element
div {
width: 200px;
height: 100px;
position: relative;
background: grey;
}
div:after {
bottom: 0;
position: absolute;
content: "";
width: 50px;
height: 5px;
background: green;
box-shadow: 50px 0 0 0 red, 100px 0 0 0 orange, 150px 0 0 0 green;
}
<div></div>
Same thing on a larger div will be like this
div {
width: 500px;
height: 100px;
background: orange;
position: relative;
}
div:after {
bottom: 0;
position: absolute;
content: "";
width: 100px;
height: 5px;
background: green;
box-shadow: 100px 0 0 0 darkred, 200px 0 0 0 red, 300px 0 0 0 yellow, 400px 0 0 0 tomato;
}
<div></div>
I have taken what harry had and amended it to suit my needs. I now have:
border-image: linear-gradient(to right, #8CC63F 0%, #006F3B 25%, #ED1C24 25%, #9B1B1E 50%, #85CDEC 50%, #217EC2 75%, #FFC20E 75%, #F04E23 100%);
border-image-slice: 3;
border-image-width: 0px 0px 4px 0px;
border-image-repeat: round;
This is the best solution for my needs.
Complicated but cool solution: Use SVG (e.g. <svg> tag), add 4 paths, assign different stroke-dasharray and stroke-color attributes.
Simpler and still cool solution: Try border-image. (See Harry's answer)
Very simple solution if you just need one border: Create an image, but it as the background image, repeat it only on one axis, position it at the edge of the container, e.g. (for bottom border)
.container {
background-image: url(image.png);
background-repeat: repeat-x;
background-position: bottom left;
}
you can try this one:
.solid{
width: 300px;
border-image: linear-gradient(to right, red 25%, blue 25%, blue 50%, green 50%, green 75%, orange 75%);
border-image-slice: 4;
}
DEMO
Best solution is with linear-gradient. Definitely.
But someone who's the beginner in this could find this solution useful. By using 2-3-4 colors or even more, this is the right way to do them. Not the best solution for this question, but maybe someone while reading this wants to understand better how do the colors with borders work.
<html>
<head>
<style>
p.one {
border-style: solid;
border-color: #0000ff;
}
p.two {
border-style: solid;
border-color: #ff0000 #0000ff;
}
p.three {
border-style: solid;
border-color: #ff0000 #00ff00 #0000ff;
}
p.four {
border-style: solid;
border-color: #ff0000 #00ff00 #0000ff rgb(250,0,255);
}
</style>
</head>
<body>
<p class="one">One-colored border!</p>
<p class="two">Two-colored border!</p>
<p class="three">Three-colored border!</p>
<p class="four">Four-colored border!</p>
</body>
</html>
I am trying to make an interesting bar I saw, Its purpose was to be a frame on the bottom of the browser with many social media links in the form of images to remind the visitor to share however this one was interesting to me because the images did not look like they could be created in the frame because from my experience image's top left has to be in the tag that created it however these were not, they produced from the frame with half the images outside (about 20px frame height and 40 image height).
First I tried by making the frame with its background gradient, limited its height put the images inside it and offsetting the images up - the bar insists on being on the top half of the images.
Next I tried making the gradient in a separate DIV inside another with contains both the images and the background, then offsetting the images down into the bar - Just pushes the bar down.
If it is possible to tell the browser to (through css properties obviously) to not consider the bar's position when coming across the images next, the images should render in the same place, then I don't see any problems offsetting them half up.
Apologies I can't share a JSFiddle as I don't know how to use images there. So heres the code I explained last.
div#shareBar div {
background: rgb(204,204,204);
background: -moz-linear-gradient(top, rgb(204,204,204) 0%, rgb(140,140,140) 16%, rgb(204,204,204) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(204,204,204)), color-stop(16%,rgb(140,140,140)), color-stop(100%,rgb(204,204,204)));
background: -webkit-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: -o-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: -ms-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: linear-gradient(to bottom, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cccccc', endColorstr='#cccccc',GradientType=0 );
border-top: 1px solid black;
height: 26px;
}
HTML:
<div id="shareBar" style="border: 1px solid red;">
<img src="Images/facebook.png"/>
<img src="Images/Twitter.png" />
<img src="Images/G+.png" />
<img src="Images/Letter.png" />
<div></div>
The images are 32x32 icons, so if the images where to be in the middle the padding would have to be 10px.
Here's how I would do it:
HTML
<div id="socialBar">
Facebook
Twitter
G+
Email
</div>
Note no secondary div
CSS
#socialBar {
height:48px;
padding-left:10px;
background: rgb(255, 255, 255);
/* Old browsers */
background: -moz-linear-gradient(top, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(50%, rgba(255, 255, 255, 1)), color-stop(51%, rgba(0, 0, 0, 1)), color-stop(53%, rgba(204, 204, 204, 1)), color-stop(73%, rgba(140, 140, 140, 1)), color-stop(100%, rgba(204, 204, 204, 1)));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* IE10+ */
background: linear-gradient(to bottom, rgba(255, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(204, 204, 204, 1) 53%, rgba(140, 140, 140, 1) 73%, rgba(204, 204, 204, 1) 100%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#cccccc', GradientType=0);
/* IE6-9 */
}
#socialBar a
{
display:inline-block;
width:32px;
height:32px;
background-image:url(http://cdn.robcubbon.com/wp-content/uploads/2012/02/social-media-gif.gif);
/*PLease use your own image preferably one with a trasparent background*/
text-indent:-999px;
background-position: 0 -32px;
}
#socialBar a.facebook
{
background-position: -96px -32px;
}
#socialBar a.facebook:hover
{
background-position: -96px 0;
}
#socialBar a.twitter
{
background-position: -128px -32px;
}
#socialBar a.twitter:hover
{
background-position: -128px 0;
}
#socialBar a.email
{
background-position: -64px -32px;
}
#socialBar a.email:hover
{
background-position: -64px 0;
}
#socialBar a.gPlus
{
background-position: 0 -32px;
}
#socialBar a.gPlus:hover
{
background-position: 0 0;
}
Example: http://jsfiddle.net/b34Gs/
How It Works
I used http://www.colorzilla.com/gradient-editor/ to edit you gradient to stop halfway up the bounding div which is given a fixed height.
Next I've set up the a tags to be inline-blocks to be the height and width of the icons. Then the inner text is shifted out of the viewport with text-indent.
I have then used CSS Spriting to give the icons the appropriate background using only one image.
As an added bonus, I've added a simple hover effect, again ussing the sprite, by shifting the background image.
Update
So baisically there is no "bar". What there is, is a fairly complicated gradient that is white for the top 50% set as the background of a div. This gives the appearance of the link icons being partially embeded in a "bar". This can be demostrated by replacing the gradient with a solid background colour: http://jsfiddle.net/b34Gs/2/.
Plan B
In your question, you mention "disabling influence". My above solution does not do this, it provides the illusion of it by manipulating the background gradient. What you are referring to is known as removing an element from the natural flow of the document. This is commonly done in two ways: float:left|right or position:absolute;. As a matter of personal preference, if I can keep elements in their natural flow, I will.
For my following examples the HTML is the same as the above. I have also restored your original, full-height gradient to #scocialBar.
Floats
#socialBar a
{
position:relative; //New
float:left; //New
top:-16px; //New
margin-right:5px; //New
display:inline-block;
width:32px;
height:32px;
background-image:url(http://cdn.robcubbon.com/wp-content/uploads/2012/02/social-media-gif.gif);
text-indent:-999px;
background-position: 0 -32px;
}
position:relative; performs the function of indicating that offsets are relative to the elements' 'natural' position. top:-16px; is indicating that the elements' top edge is offset by 16px. margin-right:5px; gives some horizontal spacing to the <a> tags.
Example: http://jsfiddle.net/b34Gs/4/
Absolute Positioning
Add position:relative to the #scocialBar style. This performs the function of indicating that child elements are positioned relative to this element. As we are adding position:absolute to the child <a> elements we have to explicitly position them as they will default to the top, left corner of their nearest ancestor element with position:relative
#socialBar a
{
position:absolute;
top:-16px;
display:inline-block;
width:32px;
height:32px;
background-image:url(http://cdn.robcubbon.com/wp-content/uploads/2012/02/social-media-gif.gif);
text-indent:-999px;
background-position: 0 -32px;
}
#socialBar a.facebook
{
background-position: -96px -32px;
}
#socialBar a.twitter
{
left:50px;
background-position: -128px -32px;
}
#socialBar a.email
{
left: 130px;
background-position: -64px -32px;
}
#socialBar a.gPlus
{
left: 90px;
background-position: 0 -32px;
}
Example: http://jsfiddle.net/b34Gs/1/
NOTE I have borrowed the sprites from some one elses website for this example. You whould use your own and makesure that it has a transparent background so the rounded edges are handled better than what the example has.
In particular, it has several solution for positioning. my example used minus margin but also you can use position, background-image, etc.
HTML:
<div id="shareBar" style="border: 1px solid red;">
<div class="bar">
<img src="http://static.iconarchive.com/static/images/social/twitter-icon.png"/>
<img src="http://static.iconarchive.com/static/images/social/facebook-icon.png" />
</div>
</div>
CSS:
div#shareBar .bar {
margin-top: 25px;
background: rgb(204,204,204);
background: -moz-linear-gradient(top, rgb(204,204,204) 0%, rgb(140,140,140) 16%, rgb(204,204,204) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(204,204,204)), color-stop(16%,rgb(140,140,140)), color-stop(100%,rgb(204,204,204)));
background: -webkit-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: -o-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: -ms-linear-gradient(top, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
background: linear-gradient(to bottom, rgb(204,204,204) 0%,rgb(140,140,140) 16%,rgb(204,204,204) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cccccc', endColorstr='#cccccc',GradientType=0 );
border-top: 1px solid black;
height: 26px;
}
div#shareBar .bar img {
margin-top: -25px;
}
I have a simple html, but I'm not sure if what I want to do (the way I want to do it) is possible..
<div class="container">
<img src="..." />
</div>
.container has some sort of gradient background, in this case a common black bottom for text
background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0) 65%, rgba(47, 39, 39, 0.7));
this is simulated in http://jsfiddle.net/9WQL6/
I want the dark bottom to be in front of the picture, not behind it.
I can't use a background-image for the image because the css is precompiled.
Is this possible?
Another way to go is with a pseudo-element (IE8+)
JSfiddle Demo
CSS
.container{
max-width: 200px;
border: 1px solid black;
position: relative;
}
.container img{
max-width: 200px;
}
.container:after {
position: absolute;
content:" ";
top:0;
left:0;
height:100%;
width:100%;
background: -webkit-gradient(top, from(rgba(255, 255, 255, 0)), color-stop(0.65, rgba(255, 255, 255, 0.7)), color-stop(1, rgba(47, 39, 39, 0.5)));
background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0) 65%, rgba(47, 39, 39, 0.7));
background: -moz-linear-gradient(top, rgba(255, 255, 255, 0) 65%, rgba(47, 39, 39, 0.7));
background: -ms-linear-gradient(top, rgba(255, 255, 255, 0) 65%, rgba(47, 39, 39, 0.7));
background: -o-linear-gradient(top, rgba(255, 255, 255, 0) 65%, rgba(47, 39, 39, 0.7));
background: linear-gradient(top, rgba(255, 255, 255, 0) 65%, rgba(47, 39, 39, 0.7));
}
Give the image negative z-index:
.container > img {
position: relative;
z-index: -1;
}
You can do this by adding a diffrent div in your container and apply the gradient on that div. The image will be in .container.
You put the containerdiv on position relative and the gradientdiv on absolute and make it the same width and height as the containerdiv.
In my example I gave the gradientdiv the class gradient
<div class="container">
<div class="gradient">
</div>
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Smiley.svg/800px-Smiley.svg.png" />
</div>
example: http://jsfiddle.net/9WQL6/9/