Apply gradient on image - css

Here's a JsFiddle.
I have an transformed image and I would like to add a gradient (black to transparant) on it.
HTML :
<div class="contentwrap">
<div class="perspectiveDiv">
<img src="http://image.noelshack.com/fichiers/2014/34/1408372755-black-card.png" class="img" />
</div>
</div>
CSS :
.contentwrap {
margin: 0 auto;
max-width: 600px;
height: 100%;
display: table;
padding-top: 150px;
}
.perspectiveDiv{
perspective:750px;
position: relative;
left: 0;
top: 0;
}
.img{
position: absolute;
top: -152px;
left: 25px;
transform: rotateX(60deg);
max-width: 250px;
-webkit-box-shadow: 0 8px 6px -6px rgba(0, 0, 0, 0.8);;
-moz-box-shadow: 0 8px 6px -6px rgba(0, 0, 0, 0.8);;
box-shadow: 0 60px 45px -20px rgba(0, 0, 0, 0.8);;
-moz-border-radius: 15px;
border-radius: 16px;
background: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
}
Here is the kind of result that I need (made with photoshop) :
I found how to apply a gradient on a background image, but not a standard image...
Is it possible to do what I need ?
Can you help me to do it ? It could be very simple but I'm a beginner and I didn't manage to do it...

Related

How to navbar sticky over a slider image

I have a navbar like this, please look the picture
this is the css code
.home-upperbar-row{
background-color: #ffffff;
z-index: 15;
position: -webkit-sticky;
position: sticky;
top: 0;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
width: unset;
height: 100%;
left: 1vw;
border-bottom-left-radius: 25px;
border-bottom-right-radius: 25px;
transform: scale(1,1) translate(0%,0%);
}
I want the red marked part in the top image but doesn't change the scale, how?
more or less the desired look like this
the picture was obtained when I scroll on the page

How to create rounded shadow?

Many times I created simple shadows but now I need to create rounded shadow. Like on the picture
Is it possible to do this with CSS??
THIS IS MY CODE:
-webkit-box-shadow: -2px 0px 79px -2px rgba(0,0,0,0.75);
-moz-box-shadow: -2px 0px 79px -2px rgba(0,0,0,0.75);
box-shadow: -2px 0px 79px -2px rgba(0,0,0,0.75);
It looks like your example image is a linear gradient in a round container, so do that:
.round-shadow-clip {
overflow: hidden;
}
.round-shadow {
background-image: linear-gradient(rgba(0, 0, 0, 0.6), transparent 20%, transparent 80%, rgba(0, 0, 0, 0.6));
border-radius: 100%;
height: 0;
margin-left: -10%;
padding-bottom: 25%;
width: 120%;
}
html {
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAALklEQVQ4y2N89+4dA24gKCiIR5aJgQIwqnlkaGb8//8/Hun379+PBtioZko0AwAA0Ajuvut+RAAAAABJRU5ErkJggg');
height: 100%;
}
<div class="round-shadow-clip">
<div class="round-shadow"></div>
</div>
With pseudo you can do this
div {
position: relative;
height: 100px;
border-radius: 50%/40%;
overflow: hidden;
}
div::before,
div::after {
content: '';
position: absolute;
left:0; right:0; top: -5px; height: 0;
box-shadow: 0 0 25px 15px rgba(0,0,0,.5);
}
div::after {
top: auto; bottom: -5px;
box-shadow: 0 0 -25px 15px rgba(0,0,0,.5);
}
<div></div>

CSS: working with box borders

I'm trying to replicate the white box on this page, Where it says "your success".
body{
background-color:#DFDFDF;
}
.index_whitebox{
background-color: #fff;
height: 60%;
width: 25%;
position: absolute;
margin-left: 4%;
margin-bottom: 20px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
border-radius: 10px;
}
<div class="index_whitebox">
</div>
I assume there's no border-style and I use % for mobile compatibility. I can't seem to get the border right.
If you look in 'inspect element' you can actually see how they've coded it. I bunched together the main bits they use, as some used a CSS file and others were inline.
.class1 {
left: 1px;
width: 302px;
position: absolute;
top: 445px;
height: 378px;
}
.class2 {
left: 1px;
width: 302px;
position: absolute;
top: 445px;
height: 378px;
}
.class3{
border: 2px solid rgba(255, 255, 255, 1);
background-color: rgba(255, 255, 255, 1);
border-radius: 5px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
It's all in here:

My animation properties are not working simultaneously

I am trying a simple animation of div which animates when page loads. Below you can see the GIF of the animation.
Here is the code
#keyframes newActivity{
to{
position: fixed;
z-index: 100;
top: 18%;
left: 10%;
width:70%;
height:80%;
}
}
.div:first-child {
animation-name:newActivity;
animation-duration:5s;
}
div {
width: 290px;
height:200px;
float:left;
margin-right: 10px;
margin-bottom: 10px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.06);
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.06);
background-color:red;
border: 1px solid #BCBCBC;
overflow:hidden;
z-index:-10;
}
<div class='div'></div>
You can see that first it increases the width and adjust position and increase the height(Without animating it). Why is this happening? I want to animate all of these properties simultaneously.
This is happening because you have set the to height as a percentage, but height percentages are inherited; they only work when the parent element has a declared height.
Only the viewport has an inherent height set, so if you want to use height: 80% on your div, then you need to also set html, body { height: 100%; } in your CSS. The html element is the child of the viewport, and body is the child of html. This way, your div's height: 80%; can inherit all the way up through body and html to the viewport. See this example:
html, body {
height: 100%;
}
#keyframes newActivity {
to {
position: fixed;
z-index: 100;
top: 18%;
left: 10%;
width: 70%;
height: 80%;
}
}
.div:first-child {
animation-name: newActivity;
animation-duration: 5s;
}
div {
width: 290px;
height: 200px;
float: left;
margin-right: 10px;
margin-bottom: 10px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.06);
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 5px rgba(0, 0, 0, 0.06);
background-color: red;
border: 1px solid #BCBCBC;
overflow: hidden;
z-index: -10;
}
<div class="div"></div>
P.S. position is not a valid animation property. See a list of valid properties here on the Mozilla Developer Network.
P.P.S. if you want the animation to retain its state at the end, you can use animation-fill-mode: forwards;.

How to position main content below header and footer in css

I have this piece of html:
<html>
<body>
<header></header>
<div></div>
<footer></footer>
</body>
</html>
and this piece of css:
header {
width: 500px;
height: 100px;
background: red;
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.5);
z-index: 10;
}
div {
width: 500px;
height: 700px;
background: yellow;
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.5);
z-index: 5;
}
footer {
width: 500px;
height: 50px;
background: blue;
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.5);
z-index: 10;
}
You can see this also here: http://jsfiddle.net/XGTtT/ Basically, I would like to have yellow area below other two areas, but z-index doesn't seem to work. What is wrong and how to fix it?
To achieve elements which are positioned in front or below each other you will need to use a mix of absolute positioning and z-index, as z-index will not currently work with the default positioning, which is static.
Depending on what you want to achieve it may be easier to add position: relative to the divs, and then use a negative margin on the div to pull it up/below the header and footer.
header {
width: 500px;
height: 100px;
background: red;
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.5);
z-index: 10;
position: absolute;
top:0;
}
div {
width: 500px;
height: 450px;
background: yellow;
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.5);
z-index: 5;
position: absolute;
}
footer {
width: 500px;
height: 50px;
background: blue;
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.5);
z-index: 10;
position: absolute;
bottom: 0;
}
http://jsfiddle.net/XGTtT/8/
Higher number will come front, lower number will go back. A
nd give some different number for each element. Like for div 1, for header 2 and for footer 3.

Resources