box shadows on multiple elements at same level but without overlap? - css

I want to create something like the following screenshot, but I can't figure out any z-index value for which the shadow doesn't appear either over the first or second box (they are always stacked either with the first one on top, or the second).
Is there a way to achieve the following?
body { background: darkgrey; padding-top: 50px}
div { background: white; width: 200px; height: 200px; box-shadow: 0 0 20px
black; margin: auto; position: relative; }
#box-one { left: -50px; z-index: 1; }
#box-two { right: -50px; z-index: 1; }
https://codepen.io/eoghanmurray/pen/oVEEVK

If you can use filter and drop-shadow then you can apply a drop-shadow to the container. This shadow differs as it conforms to the alpha channel of the image (in this case, the outline of the content) instead of a simple rectangle:
body {
background: darkgrey;
padding-top: 50px
}
#box-one,
#box-two {
background: white;
width: 200px;
height: 200px;
margin: auto;
position: relative;
}
#box-one {
left: -50px;
z-index: 1;
}
#box-two {
right: -50px;
z-index: 1;
}
#top {
filter: drop-shadow(0 0 20px black);
}
<div id="top">
<div id="box-one"></div>
<div id="box-two"></div>
</div>

You can consider drop-shadow filter on a parent element:
body {
background: pink;
}
.b1,
.b2 {
width: 150px;
height: 150px;
background: #fff;
}
.b2 {
margin-left: 100px;
}
.container {
filter:drop-shadow(0 0 10px #000);
}
<div class="container">
<div class="b1"></div>
<div class="b2"></div>
</div>
Or use an extra element to hide the overlapping shadows:
body {
background: pink;
}
.b1,
.b2 {
width: 150px;
height: 150px;
background: #fff;
box-shadow: 0 0 13px #000;
position: relative;
}
.b2 {
margin-left: 100px;
}
.b1:before,
.b2:before {
content: "";
position: absolute;
bottom: 0px;
right: 0;
left: 0;
height: 15px;
background: inherit;
z-index: 1;
}
.b2:before {
top: 0;
bottom: initial;
}
<div class="container">
<div class="b1"></div>
<div class="b2"></div>
</div>
You can also build this using only one element:
body {
background: pink;
}
.container {
width:250px;
height:300px;
background:
linear-gradient(#fff,#fff) top left,
linear-gradient(#fff,#fff) bottom right;
background-size:150px 150px;
background-repeat:no-repeat;
filter:drop-shadow(0 0 10px #000);
}
<div class="container">
</div>

I create a new div and set some css for it.
body { background: darkgrey; padding-top: 50px}
div { background: white; width: 200px; height: 200px; box-shadow: 0 0 20px black; margin: auto; position: relative; }
#box-one { left: -50px; }
#box-two { right: -50px; }
#div1{
position:absolute;
background: white;
width:100px;
height:15px;
margin-right:10px;
box-shadow: none;
margin-top:185px;
margin-left:199px;
content: '';
z-index: 1
}
<div id="div1"></div>
<div id="box-one"></div>
<div id="box-two"></div>

A cleaner solution is to add the box-shadow to a pseudo-element like ::before or ::after and then add position:relative to a parent element.
#box-one
{
left: -50px;
}
#box-two
{
right: -50px;
}
body
{
background: darkgrey;
padding-top: 50px;
}
.box-container
{
position: relative;
z-index: 2;
}
.box
{
background: white;
width: 200px;
height: 200px;
margin: auto;
position: relative;
}
.box::after
{
content: "";
box-shadow: 0 0 20px black;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
}
<div class="box-container">
<div id="box-one" class="box"></div>
<div id="box-two" class="box"></div>
</div>

Related

Adding space between custom scrollbar and content

I have a custom scrollbar as in the following example, I want to add a space between it and the content, adding padding didn't work in this case, and we only see the padding when we reach the end of the scroll.
The space between the scrollbar and the content should always be visible, but I don't know how to achieve this.
#content {
width: 600px;
height: 400px;
margin: 0;
padding: 0;
overflow: scroll;
background: white;
padding-bottom: 20px;
}
#inner {
height: 700px;
width: 800px;
background-color: red;
}
::-webkit-scrollbar {
width: 7px;
height: 7px;
}
::-webkit-scrollbar-thumb {
background-color: #04246a;
border-radius: 30px;
}
::-webkit-scrollbar-button {
width: 0;
height: 0;
display: none;
}
::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.15);
}
<div id="content">
<div id="inner">Inner content</div>
</div>
How can I solve this?
You can try this approach with pseudo-element ::after with position: absolute. To make it effect, you also need to add another wrapper called content-container for keeping content and inner separated.
#content {
width: 600px;
height: 400px;
margin: 0;
padding: 0;
background: white;
position: relative;
}
#content-container {
width: 100%;
height: 100%;
border: 1px solid black;
overflow: scroll;
}
#content::after {
content: "";
position: absolute;
width: calc(100% - 6px); /*6px difference from your custom scrollers (1px is from the border)*/
height: 20px;
bottom: 6px; /*6px difference from your custom scrollers (1px is from the border)*/
left: 0;
background-color: blue;
z-index: 1;
}
#inner {
height: 700px;
width: 800px;
background-color: red;
transform: translateZ(0);
}
::-webkit-scrollbar {
width: 7px;
height: 7px;
}
::-webkit-scrollbar-thumb {
background-color: #04246a;
border-radius: 30px;
}
::-webkit-scrollbar-button {
width: 0;
height: 0;
display: none;
}
::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.15);
}
<div id="content">
<div id="content-container">
<div id="inner">Inner content</div>
</div>
</div>
If you want to have the same behavior for both x-axis and y-axis, you can try to apply ::before and ::after together on both sides
#content {
width: 600px;
height: 400px;
margin: 0;
padding: 0;
background: white;
position: relative;
}
#content-container {
width: 100%;
height: 100%;
border: 1px solid black;
overflow: scroll;
}
#content::after {
content: "";
position: absolute;
width: calc(100% - 6px); /*6px difference from your custom scrollers (1px is from the border)*/
height: 20px;
bottom: 6px; /*6px difference from your custom scrollers (1px is from the border)*/
left: 0;
background-color: blue;
z-index: 1;
}
#content::before {
content: "";
position: absolute;
height: calc(100% - 6px);
width: 20px;
top: 0;
right: 6px;
background-color: blue;
z-index: 1;
}
#inner {
height: 700px;
width: 800px;
background-color: red;
transform: translateZ(0);
}
::-webkit-scrollbar {
width: 7px;
height: 7px;
}
::-webkit-scrollbar-thumb {
background-color: #04246a;
border-radius: 30px;
}
::-webkit-scrollbar-button {
width: 0;
height: 0;
display: none;
}
::-webkit-scrollbar-track {
background: rgba(0, 0, 0, 0.15);
}
<div id="content">
<div id="content-container">
<div id="inner">Inner content</div>
</div>
</div>
P/s: I'm using a blue background to differentiate between content and the bottom gap. You can modify it to inherit for using content background color or any color of your choice

CSS bottom triangle background

I want to create same bottom triangle effect with background but i am not able to get this effect bottom triangle with background image.
enter image description here
i have added the code here but not getting the same effect.bottom arrow im not able to extend as in image.
.logo,.nav,.social-icons{ float:left;}
body{ color:#000; background:#ccc;}
.container{border:1px solid red;}
.clear{ clear:both;}
html,body{margin:0;padding:0;}
/*****************************
BANNER
*****************************/
.section {
height: 680px;
width: 100%;
background: url("http://i.imgur.com/YtluDV9l.jpg") no-repeat left top;
background-size:cover;
}
.bottom-container {
margin-top: -137px;
height: 100px;
width: 100%;
}
.text {
position: relative;
box-sizing: border-box;
height: 300px;
padding-top: 36px;
text-align: center;
line-height: 85px;
background: url("http:////i.imgur.com/uCYtKen.jpg") no-repeat left top;
background-clip: content-box;
overflow: hidden;
margin: 25px 0 0 0;
}
.text:before {
left: 0px;
width: 26%;
transform-origin: left bottom;
transform: skew(-134deg);
}
.text:after, .text:before {
position: absolute;
content: '';
top: 0px;
height: 35px;
background: #fff;
}
.text:after {
right: 2px;
width: 74%;
transform-origin: right bottom;
transform: skew(-226deg);
}
<body>
<!--WRAPPER:STARTS-->
<div id="wrapper">
<!--HEADER:STARTS-->
<!--BANNER:STARTS-->
<section class="section">
</section>
<div class="bottom-container">
<div class="text">Some text</div>
<div class="middle-image"></div>
<div class="right-image"></div>
</div></div>
</body>
html,body{background:url(http://i.imgur.com/ixr4wNC.jpg); height:100%;padding:0;margin:0;overflow:hidden;}
.line {
margin-top: 50px;
height: 5px;
width: 20%;
background: #fff;
position: relative;
box-sizing: border-box;
}
.line:after,
.line:before {
content: "";
position: absolute;
}
.line:after {
left: calc(100% + 2px);
height: 25px;
width: 25px;
top: -12px;
border-top: 5px solid #fff;
border-left: 5px solid #fff;
transform: rotate(225deg);
}
.line:before {
height: 100%;
top: 0;
left: calc(100% + 34px);
width: 400px;
background: inherit;
}
<div class="line"></div>
Is this the same that you are looking for?
Here is JSFiddle
Hope this helps.

foundation & scroll pane 100% issue

I have a section where it is to equal columns full width across. if you look a the 2nd column where it says content here if i do 100% on the jscroll-pane it shows horizontal bars, if i give it 98% it works properly but is not full width of the column. not sure why it adds horizontal bars to 100% but not 98%. I am not sure if foundation is causing my issue or not but if i take it out of the column and put in a row the 100% works fine just not in a large-6
html
<section id="component">
<div class="row expanded collapse">
<div class="large-6 column">
<img src="images/image.png">
</div>
<div class="large-6 column">
<div class="jscroll-pane">
Content Here
</div>
</div>
</div>
</section>
css
.jscroll-pane {
display: block;
width: 100% !important;
height: 400px;
max-height: 400px;
overflow: auto;
background-color: #fff;
}
#component {
padding: 0px;
background-color: #fff;
}
jscroll external css file
.jspContainer{
overflow:hidden;
position:relative;
height:100% !important;
width: 100% !important;
}
.jspPane{
position:absolute;
width: 100%!important;
}
.jspVerticalBar
{
position: absolute;
top: 0;
right: 0;
width: 16px;
height: 100%;
background: red;
}
.jspHorizontalBar
{
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 16px;
background: red;
}
.jspCap
{
display: none;
}
.jspHorizontalBar .jspCap
{
float: left;
}
.jspTrack
{
background: #d8d8d8;
position: relative;
}
.jspDrag
{
background: #000;
position: relative;
top: 0;
left: 0;
cursor: pointer;
}
.jspHorizontalBar .jspTrack,
.jspHorizontalBar .jspDrag
{
float: left;
height: 100%;
}
.jspArrow
{
background: #50506d;
text-indent: -20000px;
display: block;
cursor: pointer;
padding: 0;
margin: 0;
}
.jspArrow.jspDisabled
{
cursor: default;
background: #80808d;
}
.jspVerticalBar .jspArrow
{
height: 16px;
}
.jspHorizontalBar .jspArrow
{
width: 16px;
float: left;
height: 100%;
}
.jspVerticalBar .jspArrow:focus
{
outline: none;
}
.jspCorner
{
background: #eeeef4;
float: left;
height: 100%;
}
/* Yuk! CSS Hack for IE6 3 pixel bug :( */
* html .jspCorner
{
margin: 0 -3px 0 0;
}
Try this, Remove the display block and change overflow: auto to hidden; I believe this should help you.
.jscroll-pane {
width: 100% !important;
height: 400px;
max-height: 400px;
overflow: hidden;
background-color: #fff;
}

Irregular Div shape Distort one corner only

How would i create a div shape like this? I have read a lot of techniques but i could not figure this one out. Inside the div is text that should not be distorted.
Every technique is welcome it does not have to be pure css.
My HTML structure:
<div class="intro">
<div class="intro-header">
<h1>Headline WOW</h1>
</div>
<div class="intro-text">
<p>Mieleni minun tekevi, aivoni ajattelevi lähteäni laulamahan, saa'ani sanelemasaa'ani sanelema sanelemasaa'ani sanelema </p>
</div>
</div>
you could use some skewed pseudo elements for this:
.first,
.last {
text-align: center;
line-height: 80px;
height: 80px;
background: green;
position: relative;
display: inline-block;
width: 400px;
margin-bottom: 20px;
}
.first:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
height: 50%;
width: 100%;
transform: SkewY(2deg);
transform-origin: bottom left;
background: inherit;
}
.last:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 50%;
width: 100%;
transform: SkewY(2deg);
transform-origin: bottom right;
background: inherit;
}
<div class="first">FIRST LINE</div>
<div class="last">LAST LINE</div>
An alternative (possibly) would be to use a gradient (although this may lead to jagged edges). Solution credit to Harry
body {
background: -webkit-linear-gradient(0deg, crimson, indianred, purple);
}
div {
height: 400px;
width: 400px;
background: -webkit-linear-gradient(75deg, lightseagreen 45%, transparent 45%, transparent 55%, lightseagreen 55%);
}
<div></div>
You can do this with border cut-offs.
As an example:
.top {
height: 300px;
background: red;
position: relative;
width: 300px
}
.top:before {
content: '';
position: absolute;
bottom: 0;
right: 0;
border-bottom: 10px solid white;
border-right: 300px solid red;
width: 0;
}
.bottom {
height: 300px;
background: red;
position: relative;
width: 300px;
padding-top: 10px;
margin-top: 0px;
}
.bottom:before {
content: '';
position: absolute;
top: 0;
right: 0;
border-top: 10px solid white;
border-left: 300px solid red;
width: 0;
}
<div class="top">Text</div>
<div class="bottom">Text</div>
This should do it.
html,body{
margin:0;
height:100%;
}
.intro{
width:400px;
display:inline-block;
background:red;
padding:50px;
}
.intro-header,.intro-text{
width:100%;
display:inline-block;
background:#ccc;
text-align:center;
position:relative;
}
.intro-header{
margin-bottom:50px;
}
.intro-header:after{
position:absolute;
left:0;
content:"";
width: 0;
height: 0;
border-left: 400px solid transparent;
border-top: 20px solid #ccc;
}
.intro-text:after{
position:absolute;
top:-20px;
left:0;
content:"";
width: 0;
height: 0;
border-right: 400px solid transparent;
border-bottom: 20px solid #ccc;
}
Example: CodePen

How create this effect 3D with CSS3

The effect I'm trying to make is as in this image:
http://i271.photobucket.com/albums/jj146/cosmossx/footer.jpg
I've made some progress as you can see in this FIDDLE
css:
.final{ background:#000;
width:100%;}
.triangle {
border-color: white black black black;
border-style: solid;
border-width: 15px 25px 25px 25px;
height: 0px;
width: 500px;
margin: 0 auto;
}
.triangle2 {
border-color: black white white white;
border-style: solid;
border-width: 15px 25px 25px 25px;
height: 0px;
width: 500px;
margin: 0 auto;
}
HTML:
<div class="final"> <div class="triangle"></div>
<br>
<br>
<br>
<br>
<br><br>
<br>
<br>
</div>
<div class="triangle2"></div>
My question is: what would be the best way to make it?
Thanks.
Best approach would be using css transform function and pseudo-elements
DEMO
Source (using Sass and Autoprefixer for brevity):
<footer class="footer">
<div class="footer__main">
<div class="footer__inner">
<div class="footer__content">
<!-- content goes here -->
</div>
</div>
</div>
<div class="footer__bottom"></div>
</footer>
.footer {
height: 500px;
}
.footer__main {
height: 80%;
background: #eee;
}
.footer__bottom {
height: 20%;
background: darken(#eee, 20);
}
.footer__inner {
background: white;
max-width: 800px;
margin: 0 auto;
height: 100%;
padding: 0 20px;
position: relative;
}
.footer__content {
background: #eee;
height: 100%;
transform: translateY(20px);
position: relative;
&:before,
&:after {
content: "";
background: darken(#eee, 10);
width: 20px;
height: 100%;
position: absolute;
top: 0; bottom: 0;
z-index: 2;
}
&:before {
right: 100%;
transform-origin: 100%;
transform: skewY(45deg);
}
&:after {
transform-origin: 0;
left: 100%;
transform: skewY(-45deg);
}
}

Resources