I want to create a paper effect shadow using the following css, but I have 3 divs inside this a div which need to be side by side. I use float to make the divs side by side, but this makes the parent's div height smaller than the inner content. I tried clear:both and overflow: hidden to fix the issue which makes the height relative to the content but this removes the shadow effect.
CSS
.boxcontainer {
position:relative;
width:90%;
}
.boxcontainer:before,
.boxcontainer:after {
content:"";
position:absolute;
z-index:-1;
bottom:15px;
left:10px;
width:50%;
height:20%;
max-width:300px;
-webkit-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
-moz-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
-webkit-transform:rotate(-3deg);
-moz-transform:rotate(-3deg);
-o-transform:rotate(-3deg);
transform:rotate(-3deg);
}
.boxcontainer:after{
right:10px;
left:auto;
-webkit-transform:rotate(3deg);
-moz-transform:rotate(3deg);
-o-transform:rotate(3deg);
transform:rotate(3deg);
}
HTML
<div id="paperbox" class="boxcontainer">
<img class="mafacemobile" src="/images/maface.jpeg" alt="ma face" width="183px" height="183px">
<div id="textwrapper">
<h1>
FILLING MORE TEX
</h1>
<div id="icons"
<img...>
</div>
</div>
</div>
I wasn't 100% sure of exactly what you had in mind for the end result due to the minimal code you provided, but hopefully this is close!
Check out my pen for a working model: http://codepen.io/gnowland/pen/crGtE
...and here's the finished code:
HTML
<div id="paperbox" class="boxcontainer">
<div class="boxinner">
<img style="-webkit-user-select: none" src="http://placehold.it/183x183" class="mafacemobile" alt="ma face" width="183px" height="183px">
<div id="textwrapper">
<h1>FILLING MORE TEXT</h1>
<div id="icons"><img style="-webkit-user-select: none" src="http://placehold.it/50"></div>
</div>
</div>
</div>
CSS
.boxcontainer {
margin: 10px;
display: inline-block;
position: relative;
background-color: #fff;
z-index: -1;
}
.boxcontainer:before {
content:"";
position:absolute;
bottom:0;
left:0;
width:100%;
height:100%;
background-color: #fff;
-webkit-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
-moz-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
-webkit-transform:rotate(-3deg);
-moz-transform:rotate(-3deg);
-o-transform:rotate(-3deg);
transform:rotate(-3deg);
}
.boxcontainer:after {
content:"";
position:absolute;
bottom:0;
left:0;
width:100%;
height:100%;
background-color: #fff;
-webkit-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
-moz-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
box-shadow:0 15px 10px rgba(0, 0, 0, 0.7);
-webkit-transform:rotate(3deg);
-moz-transform:rotate(3deg);
-o-transform:rotate(3deg);
transform:rotate(3deg);
}
.boxinner{
position: relative;
padding: 20px;
z-index: 1;
}
.boxinner > * {
/* NOTE: This is just for demo, utilize the exact selectors in your code */
display: inline-block;
padding: 2px
}
I used your .boxcontainer as a wrapper and added an inner div (.boxinner) to hold the contents so you can pad it, etc.
The major addition was using display: inline-block. Get friendly with that property, it's awesome.
You can play around with my code on codepen and let me know if you have any follow-up questions.
Hope this solved it for you! :-)
EDIT: I just realized your original question was from 7 months ago... you've probably figured it out already but hopefully this helps someone else.
Try adding position:relative to .boxcontainer
Could you provide the CSS for .boxcontainer and it's contents, too?
And also, which container is .drop-shadow being applied to?
It would be a good idea to set up a jsfiddle
Related
How do I apply this soft shadow effect underneath the horizontal purple. rows, I want to use this effect on my website. I used the box-shadow but it didn't work.
I could imitate the effect in your sample image.
Here is what I did.
HTML
<div id="outer">
<div id="inner"></div>
</div>
CSS
#outer{
width:300px;
height:300px;
background:#383142;
}
#inner{
width:300px;
height:100px;
background:#514762;
box-shadow:0 15px 30px rgba(0, 0, 0, 0.15), 0 10px 10px rgba(0, 0, 0, 0.12);
}
I have an img tag and I want to add another gradient div layer on top of it ( that gradient div will have text).
Something like this :
I already know that I can do this with linear-gradient but I don't want that becuase not all mobile versions supports this feature.
Also - I've already seen that it can be achieved via box-shadow with inset
But it's not the same. I only want top and bottom gradient - without any differences on the edges. ( just like in my first picture here ^)
This is what i've tried : JSBIN
But again , I don't want the edges to be darker. I want only the strip in the red rectangle to be from left to right.And also - symmetric - in the bottom ( same gradient should be at the bottom).
Question
How can I fix my code to achieve straight-equal gradients in top and bottom without using linear-gradient ?
NB
I need to add text on that gradient div ( text is from DB) . So It can not be a pseudo ::before/::after element div.
By using multiple shadows you can target the sides you want.
Here done setting the spread radius (4:th parameter) of the blur to a negative value, keeping it from spreading along the sides, and use the horizontal and vertical offset of the shadow to, in this case, target only the top and bottom.
.innerDiv
{
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
background :transparent;
opacity:1;
border:solid 1px red;
padding:5px;
z-index:92299;
box-shadow:
inset 0 50px 50px -40px rgba(0,0,0,1),
inset 0 -50px 50px -40px rgba(0,0,0,1);
}
<div style='position:relative;border:solid 1px lightgray;height:400px'>
<div class='innerDiv'>
Some text
</div>
<img src='http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg' height="400px" />
</div>
Based on earlier comments, here is a pseudo element version producing the exact same result, and by using the CSS attr() avoiding the issue of compile time data in the CSS.
I also added a script to show the text can be added dynamically as well.
window.addEventListener('load', function() {
var div = document.querySelector('div');
var text = div.getAttribute('data-text');
div.setAttribute('data-text', text + ', and this were added dynamically using script');
})
div
{
position:relative;
}
div::after
{
content: attr(data-text);
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
background :transparent;
opacity:1;
border:solid 1px red;
padding:5px;
z-index:92299;
box-shadow:
inset 0 50px 50px -40px rgba(0,0,0,1),
inset 0 -50px 50px -40px rgba(0,0,0,1);
}
<div style='position:relative;border:solid 1px lightgray;height:400px' data-text="Some text set using an attribute in the markup">
<img src='http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg' height="400px" />
</div>
As I also suggested in comment that if you can achieve this using pseudo elements as ::after and ::before of your img container DOM element.
You can define the pseudo elements and then play with the box-shadow to replicating that gradient effect.
Here I have made some changes in your DOM structure as:
Code Snippet:
.img-container {
position: relative;
}
.img-container img {
max-width: 100%;
}
.img-container::after,
.img-container::before {
content: "";
display: inline-block;
position: absolute;
left: 0;
right: 0;
width: 100%;
height: 50px;
}
.img-container::before {
top: 0;
-webkit-box-shadow: 0px 25px 16px -10px rgba(0, 0, 0, 0.5) inset;
box-shadow: 0px 25px 16px -10px rgba(0, 0, 0, 0.5) inset;
}
.img-container::after {
bottom: 0;
-webkit-box-shadow: 0px -25px 16px -10px rgba(0, 0, 0, 0.5) inset;
box-shadow: 0px -25px 16px -10px rgba(0, 0, 0, 0.5) inset;
}
<div class="img-container">
<img src='http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg' height="400px" />
</div>
(using the answer of #vivekkupadhyay as example) you could just make an overlay div and give this the inset shadow. Then you can add whatever content you want.
.img-container,
.img-overlay {
position: absolute;
top: 0;
left 0;
}
.img-container {
overflow: hidden;
}
.img-container img {
max-width: 100%;
}
.img-overlay {
width: 120%;
height: 100%;
-webkit-box-shadow: inset 0px 0px 25px 5px rgba(0,0,0,0.75);
box-shadow: inset 0px 0px 25px 5px rgba(0,0,0,0.75);
margin-left: -25px;
padding: 0px 30px;
color: white;
}
<div class="img-container">
<img src='http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg' height="400px" />
<div class="img-overlay">
some text
</div>
</div>
EDIT: you could also make two seperate overlay div's for top and bottom if you want the to both have content, but this is just a quick example.
This question already has answers here:
How to darken a background using CSS?
(11 answers)
Closed 6 years ago.
I have a jumbotron from bootstrap and I want to darken its background without touching the text which is entered in it. Is there a way to do such a thing?
I have looked everywhere, but all solutions I've found darken the text as well.
What I have so far:
.mainJumbotron {
margin: 0px;
height: 250px;
text-align: center;
background-image: url(http://i.imgur.com/qj2w73W.png);
background-repeat: no-repeat;
background-size: cover;
}
<div class="jumbotron mainJumbotron">
<h1 style="">Hakkımızda</h1>
</div>
try something like this:
In your jumbotron class, give it a little more CSS by adding position:relative; to it if it's not already there. That will allow the next step to be positioned inside of that box.
Then, add an :after pseudo element. with the following CSS
.jumbotron:after {
content:"";
display:block;
width:100%;
height:100%;
background-color:rgba(0,0,0,0.5);
position:absolute;
top:0;
left:0;
z-index:1 /*Added this in the updated */
}
the background-color shade is controlled by the final value. 0.5 is 50% opacity, raise to 1 or lower to 0 to get your desired darkness.
UPDATE What has been pointed out is that anything inside of the box is covered by the new pseudo element. Here's a cheap fix. Add z-index:1; to your :after alement, then add the below
.jumbotron > * {
position:relative;
z-index:2;
}
Thanks to cale_b https://jsfiddle.net/e8c3ex0h/3/
You can try the following in you CSS to see if you get the desired result
#element {
-webkit-box-shadow: inset 0px 50px 100px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: inset 0px 50px 100px 0px rgba(0, 0, 0, 1);
box-shadow: inset 0px 50px 100px 0px rgba(0, 0, 0, 1);
}
This is how to do it :
body, h1 {
margin: 0;
}
.mainJumbotron {
margin: 0px;
height: 250px;
text-align: center;
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
url(http://i.imgur.com/qj2w73W.png);
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
h1 {
color: #fff;
}
<div class="jumbotron mainJumbotron">
<h1 style="">Hakkımızda</h1>
</div>
(see also this Fiddle)
I have two elements, one for header and the other for navbar.
I want to apply z-indexproperty to make the header on the top, then the navbar on the bottom.
HTML
<div id="main">
<div id="header"><h2 id="logo">Logo</h2></div>
<div id="navBar"><span>x</span></div>
</div>
CSS
div#header {
height:70px;
background-color:#fff;
border-bottom:1px solid rgba(0, 0, 0, 0);
box-shadow:0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 1px 0 0 rgba(0, 0, 0, 0.1);
z-index:20;
}
div#navBar {
height:50px;
padding-right:240px;
line-height:45px;
background:yellow;
z-index:21;
}
div#header #logo {
position:relative;
right:-20px;
bottom:-20px;
}
Also you can see the demo on jsfiddle
Why this problem occur ?
And how to solve it ?
For z-index to work you need to set position on those elements: absolute, relative, etc.
You mean the header text appearing above the nav bar? Perhaps you could try moving the header div tag into the beginning of the nav bar div tag.
It will work if you just switch the z-indices. Lower index means bottom. You have the larger index on the bottom element. Change 21 to 19. Also You need to position (set the position property to anything other than static, you probably want relative in this case) anything you want to give a z-index to.
div#header {
position: relative
height:70px;
background-color:#fff;
border-bottom:1px solid rgba(0, 0, 0, 0);
box-shadow:0 2px 2px 0 rgba(0, 0, 0, 0.1), 0 1px 0 0 rgba(0, 0, 0, 0.1);
z-index:20;
}
div#navBar {
position: relative
height:50px;
padding-right:240px;
line-height:45px;
background:yellow;
z-index:19;
}
div#header #logo {
position:relative;
right:-20px;
bottom:-20px;
}
I cannot get box-shadow to create a shadow around the entire perimeter of a div. The following works in FireFox, however not in IE 11.
I have tried the following: Internet Explorer - CSS Shadow All Around
Here is a JSFiddle for the problem.
CSS:
.addAccountPanel
{
width:250px;
height:200px;
margin:auto;
background-color: rgba(0,0,0, .2);
position:relative;
box-shadow: 0px 0px 4px #004C7E;
}
HTML:
<div class="addAccountPanel"> </div>
There is a fourth parameter in the box-shadow that lets you increase the size of the shadow, and makes it more visible
.addAccountPanel
{
width:250px;
height:200px;
margin:auto;
background-color: rgba(0,0,0, .2);
position:relative;
box-shadow: 0px 0px 4px 2px #004C7E;
}
fiddle