CSS Page 底部连同左右阴影一起剥离

标签 css shadow css-shapes

我想用 css shadow 创建这个页面(见图片)。这可能吗?那么要让页面剥离 css 框阴影左右底部和左右阴影? enter image description here

最佳答案

您可以使用伪元素 :before:after 来做到这一点。创建两个具有自己的框阴影的新区域并将它们放置在需要的位置,您可以创建阴影随着页面向下而变大的错觉。

body {
  background: lightgrey;
}
div {
  background: white;
  margin: 40px auto;
  height: 500px;
  width: 300px;
  position: relative;
  padding: 10px;
}
div:before,
div:after {
  height: 97%;
  z-index: -10;
  position: absolute;
  content: "";
  bottom: 15px;
  left: 8px;
  width: 30%;
  top: 2%;
  max-width: 300px;
  background: transparent;
  box-shadow: -10px 0px 5px rgba(0, 0, 0, 0.3);
  transform: rotate(1deg);
}
div:after {
  transform: rotate(-1deg);
  right: 8px;
  left: auto;
  box-shadow: 10px 0px 5px rgba(0, 0, 0, 0.3);
}
<div>
  test
</div>

另一种方法是使用 CSS 转换来改变单个 :before 伪元素的视角。

这是由 Harry 完成的**

body {
  background: lightgrey;
}
div {
  background: white;
  margin: 40px auto;
  height: 500px;
  width: 300px;
  position: relative;
  padding: 10px;
  box-shadow: 10px 0px 5px -10px gray, -10px 0px 5px -10px gray;
}
div:after {
  content: '';
  position: absolute;
  bottom: 10px;
  left: 0px;
  height: 50%;
  width: 100%;
  transform-origin: 50% 100%;
  transform: perspective(100px) rotateX(1deg);
  box-shadow: 5px 0px 10px gray, -5px 0px 10px gray;
  z-index: -1;
}
<div></div>

关于CSS Page 底部连同左右阴影一起剥离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30360606/

相关文章:

css - 如何在没有 rgba 的情况下仅在按钮文本颜色上设置不透明度?

html - 如何使整个自定义复选框/Div 可点击——而不仅仅是标签 + 输入

php - 如何处理 Internet Explorer 8 的第 n 个 child

jquery - 将阴影添加到文本框 onFocus

wpf - 如何在silverlight中在网格周围设置阴影?

HTML 和 CSS 不规则三 Angular 形图片库

css - 如何使用 Asp.Net MVC Razor 语法通过循环连续显示 3 个元素

html - Internet Explorer 中链接上的文本阴影?

html - 如何使用 HTML5 和 CSS 3 将按钮放置在一个圆圈周围?

css - 在斜线上对齐文本