内容简介:Box shadow onLet’s take a look at a default configuration ofIn the example above the first property number is the origin of the
Box shadow on HTML elements has been widely supported across most browsers for a while now, but I find the default options don’t allow for much visual manipulation of the shadows in general.
Let’s take a look at a default configuration of box-shadow
:
.box-container { box-shadow: 0 4px 8px rgba(0,0,0,0.3); }
In the example above the first property number is the origin of the x-axis , the second number is the origin of the y-axis and the third is the amount of blur .
We should also add some minimal styling to cleanup the .box-container
a little bit for our example:
<div></div>
.box-container { box-shadow: 0 4px 8px rgba(0,0,0,0.3); /* Styles to make it less ugly */ background: white; border-radius: 10px; border: 1px solid #eee; height: 200px; padding: 10px; position: relative; width: 250px; }
Which would render as this:
Not bad – but we can do a lot better than this.
Please sir, I want some more (depth)
We just need to add a simple child div
(or use a pseudo
element if you prefer) inside our main element we want to apply the shadow to:
<div> <div></div> </div>
Now we make our inner child element absolute
and set it’s height
and width
dynamically to be slightly smaller than it’s parent (percentages work best for this). Remember to set this child element behind it’s parent by adding z-index: -1
.
.box-container { /* No box-shadow needed on this element anymore */ /* Styles to make it less ugly */ background: white; border-radius: 10px; border: 1px solid #eee; height: 200px; padding: 10px; position: relative; width: 250px; } .box-container-inner { bottom: 0; /* The box-shadow is added here now */ box-shadow: 0 4px 12px rgba(0,0,0,0.3); height: 94%; left: 3%; position: absolute; width: 94%; z-index: -1; }
Which will make the drop-shadow render with a little more realistic depth:
But wait – there’s more!
We could stop now and have a decent drop-shadow that is certainly easier on the eyes – but we can make this even better with one extra property – filter:blur();
.
So your final code would look like this:
.box-container { /* Styles to make it less ugly */ background: white; border-radius: 10px; border: 1px solid #eee; height: 200px; padding: 10px; position: relative; width: 250px; } .box-container-inner { bottom: 0; box-shadow: 0 4px 12px rgba(0,0,0,0.3); filter: blur(6px); height: 94%; left: 3%; position: absolute; width: 94%; z-index: -1; }
Which renders out into a much smoother blend of a drop-shadow, creating a more realistic illusion of depth:
Comments
No comments (yet)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
需求
[美] 亚德里安•斯莱沃斯基(Adrian J. Slywotzky)、[美]卡尔•韦伯 (Karl Weber) / 魏薇、龙志勇 / 浙江人民出版社 / 2013-6 / 64.9
《财富汇•需求:缔造伟大商业传奇的根本力量》内容简介:需求,是缔造伟大商业传奇的根本力量。《财富汇•需求:缔造伟大商业传奇的根本力量》呈现了人们无法拒绝、竞争对手无法复制的需求创造的六大关键,在人们无奈接受的现状和心中真正期待的理想的这道鸿沟之上,架设起了一道桥梁。 创造需求,需要解开一个谜团,这个谜团是人类学、心理学、科技、设计、经济学、基础设施以及其他众多因素综合而成的奇特组合。《财富汇......一起来看看 《需求》 这本书的介绍吧!