html/css make multiple sections that drop shadow one on another - html

I have multiple sections placed one after another, each of them should drop shadow on the next one. Number of sections might change
My current idea is to create about 10 css rules like
section {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
section:nth-child(1){
z-index:10
}
section:nth-child(2) {
z-index:9
}
...
This approach has obvious flaw, so my question is - is there more elegant way to achieve this using only html/css?
Set z-index automatically somehow or make shadows in completely different way?

It's actually possible without using JavaScript or a pseudo-element.
Just using the transform-style: preserve-3d property and a specific rotation.
.section {
height: 32px;
width: 100%;
background: white;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
transform: rotateX(1deg);
}
.wrapper {
transform: rotateX(-1deg);
transform-style: preserve-3d;
}
<div class="wrapper">
<div class="section"></div>
<div class="section"></div>
<div class="section"></div>
<div class="section"></div>
</div>

It's impossible to do it via html/css. But you can use javascript:
for (var i=$("section").length; i > 1; i++){
$("section:nth-child(" + i +")").css ({"z-index":i});
}
And css:
section {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

Related

Fixed Nav Issue

Im trying to create a stick nav. However on doing so, the nav goes into the background.
I've set the position on the nav div like so,
.site-header {
...
position: fixed;
}
However, this has worked as expected, as mentioned above. Is there anything else I should be adding, to ensure the div is ontop and fixed.
https://jsfiddle.net/fe6jc8nu/
Thanks,
Add z:index: 9; to .site-header rule:
.site-header {
background-color: #fff;
padding-bottom: 25px;
padding-top: 25px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
position: fixed;
z-index: 9;
}

How to achieve stacked styling effect with html and css?

How is this styling achieved using html and css? It looks like three divs, however when inspected through the console, it appears that ::before might be being used.
Also does anyone know what this kind of style might be called so I can update the title of this question to be more specific?
I took this image and example from here http://todomvc.com/examples/react/#/
Looking into code, it's pretty simple to find how they achieved this effect. Stacked box-shadows.
.footer:before {
content: '';
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 50px;
overflow: hidden;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
0 8px 0 -3px #f6f6f6,
0 9px 1px -3px rgba(0, 0, 0, 0.2),
0 16px 0 -6px #f6f6f6,
0 17px 2px -6px rgba(0, 0, 0, 0.2);
}
But surely there are more ways of doing this, depending on your needs.

Responsive box needs to fit the rest of the page

I sit with a little teasing at the Responsive design on my page...
In a PC browser all is as it should ..
But on other mobile devices, the boxes not really fit ...
The site is www.iværksætterpodcast.dk
here can you see the problem from an iphone 5 browser.
http://mobiletest.me/iphone_5_emulator/ # u = http://iværksætterpodcast.dk
So if you click load the page from a mobile browser and brows through the menu, you'll see the page doesn't fit.
I tried to chance this:
page_content {
width: 824px;
opacity: 0.8;
overflow: hidden;
margin: 50px auto 120px;
padding: 5px 0 30px;
-moz-box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
}
but that doesn't help.
I think its something with: media queries maybe?
Well if you some kind can install a plugin with a responsive menu which will fix my other issue, that would be fine aswell.
Hope you can help ...
How would something like this do for you. You can expand the window to see it is responsive.
.wrap {
max-width:960px;
margin:0 auto;
}
.page-content {
width: 92%;
float:left;
opacity: 0.8;
overflow: hidden;
margin:10px 2%;
padding:20px 2%;
-moz-box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
}
Check it out on fiddle

how to overlap two div in css?

I have two div likes ,
<div class="imageDiv"></div>
<div class="imageDiv"></div>
and css class ,
.imageDiv
{
margin-left: 100px;
background: #fff;
display: block;
width: 345px;
height: 220px;
padding: 10px;
border-radius: 2px 2px 2px 2px;
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
}
You can see the result Here :)
I want to overlap this two div likes ,
add to second div bottomDiv
and add this to css.
.bottomDiv{
position:relative;
bottom:150px;
left:150px;
}
http://jsfiddle.net/aw8RD/1/
See demo here
you need to introduce an additiona calss for second div
.overlap{
top: -30px;
position: relative;
left: 30px;
}
I edited you fiddle
you just need to add z-index to the front element and position it accordingly.
check this fiddle , and if you want to move the overlapped div you set its position to absolute then change it's top and left values
Why don't you use just one div and then use pseudo element :: before or ::after and set position of that pseudo element to absolute then set top: 100px and left 100px

How to get Outer div to Grow alongside Inner div

I have a container div which, inside, has an inner div. I would like it for my outer div to grow (in height) alongside the contents of its inner div. I've set a minimum height, however the size of the outer div never has a height different from the minimum one I have set.
This is the html:
<div id="containerDiv">
<div class="innerDiv">
<div id="header" class="layout">...</div>
<div id="mainMenu" class="layout">...</div>
<div id="content" class="layout">...</div>
<div id="footer" class="layout">...</div>
</div>
</div>
This is the CSS:
#containerDiv {
background-image: url('/Content/images/backgroundimage.png');
min-height: 760px;
width: 100%;
border-radius: 1px;
box-shadow: 0 96px 86px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
overflow: auto;
}
.innerDiv{
border-radius: 1px;
-webkit-border-radius: 1px;
box-shadow: 0 0 86px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
position: absolute;
background-color: white;
}
This fiddle should help see my problem. The red div should be the same height as the white one. The width is ok, it is supposed to be 100%.
http://jsfiddle.net/arrsoph87/euB8H/
Based on this solution I tried setting the overflow property to auto (in the container), with no luck.
Based on this solution, I tried setting the container's property float, to left. This didn't work either.
I also tried adding right after this line
<div id="footer" class="layout">...</div>
(meaning, right before closing the inner div), to add this line based on another post
<div style="clear:both;"></div>
Also couldn't get this to work. Any suggestions?
Change overflow: auto to overflow: hidden. That oughta work.
#containerDiv {
background-image: url('/Content/images/backgroundimage.png');
min-height: 760px;
width: 100%;
border-radius: 1px;
-webkit-border-radius: 1px;
-o-border-radius: 3px;
box-shadow: 0 96px 86px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
overflow: hidden; // <-------
}
This typically happens if your innerDiv is floating right or left. You seem to not have added the class definition of innerDiv.
Usually the solution to this is to add after the end tag of innerDiv (and not before it).
Ok, the problem seemed to be that the position:absolute property of the innerDiv. I changed it to relative and it worked. The following would be the relevant HTML:
<div id="containerDiv">
<div class="innerDiv">
<div id="header" class="layout">HEADER</div>
<div id="mainMenu" class="layout">MAIN MENU</div>
<div id="content" class="layout">CONTENT</div>
<div id="footer" class="layout">FOOTER</div>
</div>
</div>​
And the CSS:
#containerDiv
{
background-image: url('/Content/images/backgroundimage.png');
min-height:760px;
width: 100%;
border-radius: 1px;
-webkit-border-radius: 1px;
box-shadow: 0 96px 86px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
overflow:hidden; /*added*/
/* removed overflow:auto; */
}
.innerDiv
{
border-radius: 1px;
-webkit-border-radius: 1px;
box-shadow: 0 0 86px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
position: relative; /*added*/
/*removed position:auto;*/
left:230px; /*added*/
background-color:white;
width: 100px;
}​
I placed it in this new fiddle.
http://jsfiddle.net/arrsoph87/BC5n8/