Box-shadow of div over inner div - html

I have an outer div with box-shadow and I want this to appear over an inner div. But it always appears under it. The jsfiddle is here.
My HTML is:
<div class="wrapper">
<div class="inner">
</div>
</div>
And CSS:
.wrapper {
width: 200px;
height: 100px;
border: 1px grey solid;
box-shadow: inset 40px 0 10px -10px #bbbbbb;
}
.inner{
width: 180px;
height: 80px;
margin: 10px;
background-color: lightblue;
}
Is it possible to get it so that the box-shadow appears over the inner blue div? The semantics of the HTML cannot change.

Set the position of the child to relative and the z-index to -1:
.wrapper {
width: 200px;
height: 100px;
border: 1px grey solid;
box-shadow: inset 40px 0 10px -10px #bbbbbb;
}
.inner {
width: 180px;
height: 80px;
margin: 10px;
background-color: lightblue;
position:relative;
z-index:-1;
}
<div class="wrapper">
<div class="inner">
</div>
</div>

update the styles of inner class with position absolute and give z-index: -1;;
.inner {
width: 180px;
height: 80px;
margin: 10px;
background-color: lightblue;
position:relative;
z-index:-1;
}
Here is the updated jsFiddle

You can do what you are wanting without the inner container as well.
http://codepen.io/creativenauts/pen/rLWZqp
* {
box-sizing: border-box;
}
.wrapper {
width: 200px;
height: 100px;
border: 20px solid #fff;
background-color: lightblue;
box-shadow: 0px 0px 1px rgba(#000, 0.5);
position: relative;
&:before {
position: absolute;
content: '';
width: 100%;
height: 100px;
top: -20px;
left: -20px;
box-shadow: inset 40px 0 10px -10px #bbbbbb;
}
}

Related

Inline block elements positioned with one fixed and the other relative

I am trying to get two inline-block elements to position where the left side #faqBlock remains positioned fixed and then #blueBox is positioned relative. This basic functionality is working in the snippet, but the containerRight is overtaking containerLeft.
How can I main the containers width and inline-block display while having #faqBlock being positioned fixed?
#page-wrap {
margin-top: 70px;
max-width: 100%;
}
#containerLeft,
#containerRight {
display: inline-block;
vertical-align: top;
box-sizing: border-box;
height: 200vh;
}
/*-- Container Left --*/
#containerLeft {
width: 40%;
position: fixed;
}
#faqBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: #b82222;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
#blueBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: blue;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
/*-- Container Right --*/
#containerRight {
width: 60%;
position: relative;
}
<div id="page-wrap">
<div id="containerLeft">
<div id="faqBlock">
gfsag
</div>
</div>
<div id="containerRight">
<div id="blueBlock">
gfsag
</div>
</div>
</div>
Elements with position fixed aren't in the regular flow, so it won't ever take up space in the way you are imagining. You can add margin-left: 40%; (equal to the width of the left container) onto the right container to make it look like it's holding space.
If this isn't what you are looking for, let me know!
#page-wrap {
margin-top: 70px;
max-width: 100%;
}
#containerLeft, #containerRight {
display: inline-block;
vertical-align: top;
box-sizing: border-box;
height: 200vh;
}
/*-- Container Left --*/
#containerLeft {
width: 40%;
position: fixed;
}
#faqBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: #b82222;
box-shadow: 10px 5px 5px rgba(0,0,0,0.12);
}
#blueBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: blue;
box-shadow: 10px 5px 5px rgba(0,0,0,0.12);
}
/*-- Container Right --*/
#containerRight {
width: 60%;
position: relative;
margin-left: 40%;
}
<div id="page-wrap">
<div id="containerLeft">
<div id="faqBlock">
gfsag
</div>
</div><div id="containerRight">
<div id="blueBlock">
gfsag
</div>
</div>
</div>
All you need to assign is left:40% to your containerRight as it's already positioned relative
As your width of fixed container is 40%.
#page-wrap {
margin-top: 70px;
max-width: 100%;
border: 1px solid;
}
#containerLeft,
#containerRight {
vertical-align: top;
box-sizing: border-box;
height: 200vh;
border: 2px solid red;
}
/*-- Container Left --*/
#containerLeft {
width: 40%;
position: fixed;
}
#faqBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: #b82222;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
#blueBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
border: 2px solid orange;
background: blue;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
/*-- Container Right --*/
#containerRight {
left: 40%;
width: 60%;
position: relative;
}
<div id="page-wrap">
<div id="containerLeft">
<div id="faqBlock">
gfsag
</div>
</div>
<div id="containerRight">
<div id="blueBlock">
gfsag
</div>
</div>
</div>

How do i centre a div in angular 5

I am using Angular5, and I have tried to set margin: 0 auto as well as setting left: 50% and top: 50% but the margin doesn't do anything and setting left to 50% only aligns the side of the div to the middle and doesn't move the div down at all.
How do I align the div #loading to the middle?
My code:
#loading, #outlet {
width: 100%;
height: 100%;
position: absolute;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
margin: 0 auto;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
}
<div id="app">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>
I am also overlaying the #loading div over #outlet.
The problem you are having is because of the position: absolute thing that you have assigned to both #loading and #outlet. You can solve the issue with this code. Try this.
<div id="app">
<div id="wrap">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>
</div>
#wrap {
margin: 0 auto;
width: 200px;
}
#loading, #outlet {
width: 100%;
height: 100%;
position: absolute;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
margin: 0 auto;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
width: 100%;
}
To align the text in the center, use text-align: center:
#loading, #outlet {
width: 100%;
height: 100%;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
text-align: center;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
}
<div id="app">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>
To align the box in the center, use margin: auto, but DO NOT use position: absolute:
#loading, #outlet {
width: 100%;
height: 100%;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
margin: auto;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
}
<div id="app">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>
Then if you put those two together, you get:
#loading, #outlet {
width: 100%;
height: 100%;
}
#loading{
z-index: 10;
height: 100px;
width: 200px;
background-color: rgba(255,255,255,0.85);
padding: 40px;
border: 1px solid #d3d3d3;
border-radius: 5px;
margin: auto;
text-align: center;
margin-bottom:10px;
box-shadow: 0px 1px 3px rgba(0,0,0,0.5);
}
#app{
position: relative;
}
<div id="app">
<div id="outlet">
<router-outlet></router-outlet>
</div>
<div id="loading" *ngIf="data.Loading">
<h2>Loading...</h2>
</div>
</div>

Is it possible to add image as box shadow with css?

Is it possible to add image as box shadow, for example to put image with dots instead of standard shadow?
https://i.stack.imgur.com/DOJGh.png
or somehow to replace shadow from picture with dots?
to get effect like this on picture down here
http://prntscr.com/fvjnht
Did you want something like this? It's not exactly box-shadow, but it imitates it.
You can set whatever image you like as a background for .image::after.
html, body {
margin: 0;
}
body {
width: 100vw;
height: 100vh;
}
.contain {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.image{
position: relative;
width: 200px;
height: 200px;
background-image: url(http://via.placeholder.com/200x200);
}
.image::after {
content: '';
background: linear-gradient(to bottom, #333, red);
position: absolute;
width: 100%;
height: 100%;
bottom: -10px;
right: -10px;
z-index: -1;
}
<div class="contain">
<div class="image"></div>
</div>
I think this is exactly what you are looking for:
body {
background: black;
}
#logo {
width: 200px;
height: 200px;
display: block;
position: relative;
}
#logo::after {
content: "";
background: url("https://rfclipart.com/image/big/3f-a9-1a/red-dotted-halftone-background-Download-Royalty-free-Vector-File-EPS-183199.jpg");
opacity: 0.4;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
border-radius: 50%;
z-index: -1;
}
img {
width: 90%;
height: 90%;
padding: 5%;
display: block;
float: left;
border-radius: 50%;
box-shadow: 0px 0px 40px #ccc;
-moz-box-shadow: 0px 0px 40px #ccc;
-webkit-box-shadow: 0px 0px 40px #ccc;
}
<div id="logo">
<img src="http://icons.iconarchive.com/icons/graphicloads/colorful-long-
shadow/256/User-icon.png" alt=""/>
</div>
Kind of like this?
.image_carousel img {
margin-right: 14px;
display: block;
float: left;
box-shadow: 3px 3px 1px #ccc;
-webkit-box-shadow: 3px 3px 1px #ccc;
-moz-box-shadow: 3px 3px 1px #ccc;
}
<div class="image_carousel"><img src="//placehold.it/300/f80/fff" alt=""/></div>
Credit goes to Joseph Marikle.
Like this?
span {
border: 2px dotted red;
display: inline-block;
}
img {
padding: 0;
margin: 0;
display: block;
}
<span class="dotted-border"><img src="http://placehold.it/200"/></span>

CSS boxshadow over an image

I want to place boxshadow on an image. I'm trying following but it just adds it behind the image, making it not visible. How that can be done?
CSS and HTML:
.box2 {
float: left;
height: 150px;
width: 150px;
box-shadow: inset 0px 0px 0px 10px #f00;
}
<div class="box2"><img src="https://farm1.staticflickr.com/502/18386328915_c63c4f6c7f_q.jpg" /></div>
Problem:
JSFiddle Demo:
http://jsfiddle.net/Lwm95h7q/
You can do this with :after, for example.
.box1{
height: 150px;
width: 150px;
background: green;
box-shadow:inset 0px 0px 0px 10px #f00;
float: left;
margin-right: 50px;
}
.box2 {
position: relative;
float: left;
height: 150px;
width: 150px;
box-shadow: inset 0px 0px 0px 10px #f00;
}
.box2:after {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
content: '';
box-shadow: inset 0px 0px 0px 10px #f00;
z-index: 1;
}
Take a look at the fiddle:
http://jsfiddle.net/skeurentjes/Lwm95h7q/5/
Just replace box-shadow with
outline: 10px solid #f00;outline-offset:-10px;
.box1{
height: 150px;
width: 150px;
background: green;
box-shadow:inset 0px 0px 0px 10px #f00;
float: left;
margin-right: 50px;
}
.box2 {
float: left;
height: 150px;
width: 150px;
outline: 10px solid #f00;
outline-offset:-10px;
}
<div class="box1">some text</div>
<div class="box2"><img src="https://farm1.staticflickr.com/502/18386328915_c63c4f6c7f_q.jpg" /></div>
This can be achieved by using an :after pseudo element with the box-shadow over the top of the img:
Add position: relative; to .box2 to allow the pseudo element to be positioned relatively to it
Add .box2:after with position: absolute; to take it out of the document flow. Set the height and width equal to the height and width of .box2 and position it to the top and left of .box2. Apply the box-shadow to this
.box1 {
background: green;
box-shadow: inset 0px 0px 0px 10px #f00;
float: left;
height: 150px;
margin-right: 50px;
width: 150px;
}
.box2 {
float: left;
height: 150px;
position: relative;
width: 150px;
}
.box2:after {
box-shadow: inset 0px 0px 0px 10px #f00;
content: "";
height: 150px;
left: 0;
position: absolute;
top: 0;
width: 150px;
}
<div class="box1">some text</div>
<div class="box2">
<img src="https://farm1.staticflickr.com/502/18386328915_c63c4f6c7f_q.jpg" />
</div>
you have not given padding so.. add this css
.box2 {
float: left;
height: 150px;
width: 150px;
box-shadow: inset 10px 10px 10px 10px #f00;
padding: 10px;
}

How Can I Make a Box Element Expand Automatically?

The link below shows a simplified version of a website I'm working on and the problem I'm presented with.
I have several encapsulated box elements. There is the main container, and several divs within that container that will hold content, as that content expands, I need the container div to expand automatically. I can't seem to accomplish this unless I add a specific height in the CSS.
JSFiddle Example
HTML:
<body>
<div id="container">
<div id="block1">
<div id="one">one</div>
<div id="two">two<br />two<br /></div>
<div id="three">three<br />three<br />three<br /></div>
<div id="four">four<br />four<br />four<br />four<br /></div>
</div>
</div>
</body>
CSS:
#container {
width: 1050px;
margin: auto;
padding: 5px;
background-color: #ededf0;
background:
url("http://wguayan.comuv.com/brushed_metal_clear_apple.jpg") repeat;
}
#one, #two, #three, #four {
border-width: 1px;
border-color: black;
border-style: solid;
background-color: white;
border-radius:6px;
-moz-border-radius:6px;
/* Firefox 3.6 and earlier */
}
#one {
width: 100px;
position: relative;
top: 0px;
left: 0px;
padding: 10px;
box-shadow: 9px 9px 12px #888888;
}
#two {
float: left;
width: 100px;
position: relative;
top: 0px;
left: 0px;
padding: 5px;
text-align: center;
box-shadow: 9px 9px 12px #888888;
}
#three {
float: left;
width: 100px;
position: relative;
top: 0px;
left: 0px;
padding: 10px;
box-shadow: 9px 9px 12px #888888;
}
#four {
float: left;
width: 100px;
position: relative;
top: 0px;
left: 0px;
padding: 10px;
box-shadow: 9px 9px 12px #888888;
}
#block1 {
width: 100%;
border-width: 1px;
border-color: black;
border-style: solid;
}
Just apply overflow: hidden to #block1