3d对图象的作用与css

时间:2017-11-30 21:31:42

标签: css transform perspective

我在PSD中有这个图像,我应该在css中创建它 enter image description here

但我不知道怎么能这样做。 这是HTML代码:

 <div class="wrapper">
                    <img src="assets/img/index.header.png" alt="">
                </div>

CSS代码:

.wrapper{
  transform-style: preserve-3d;
  transform: rotateX(-40deg) rotateY(32deg);
perspective: 1000px;
}
img{
    width:882px;
      height: 561px;
      box-shadow: rem(-20) rem(20) rem(80) 0 rgba(0, 0, 0, 0.15),
                  rem(-20) rem(20) rem(80) 0  rgba(0, 0, 0, 0.15) ;
   transform: rotateX( 90deg)  translateZ(1em);
}

但结果并不是我想要的。 我想添加 box-shadow 3d效果,就像图像一样。 这是原始图片 enter image description here

1 个答案:

答案 0 :(得分:0)

这是我根据您的要求调整转换的示例代码。

@import url(https://fonts.googleapis.com/css?family=Open+Sans);


body {
    height: 100vh;
    margin:0;
}

.thumb {
    width: 400px;
    height: 300px;
    margin: 70px auto;
    perspective: 1000px;
}

.thumb a {
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), 
		url("https://image.ibb.co/dms0AG/image.jpg");
    background-size: 0, cover;
    transform-style: preserve-3d;
    transition: all 0.5s;
}

.thumb:hover a {
    transform: rotateX(80deg);
    transform-origin: bottom;
}
.thumb a:after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 36px;
    background: inherit;
    background-size: cover, cover;
    background-position: bottom;
    transform: rotateX(90deg);
    transform-origin: bottom;
}
.thumb a span {
    color: white;
    text-transform: uppercase;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    font: bold 12px/36px "Open Sans";
    text-align: center;
    transform: rotateX(-89.99deg);
    transform-origin: top;
    z-index: 1;
}
.thumb a:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 100px 50px rgba(0, 0, 0, 0.5);
    transition: all 0.5s;
    opacity: 0.15;
    transform: rotateX(95deg) translateZ(-80px) scale(0.75);
    transform-origin: bottom;
}

.thumb:hover a:before {
    opacity: 1;
    box-shadow: 0 0 25px 25px rgba(0, 0, 0, 0.5);
    transform: rotateX(0) translateZ(-60px) scale(0.85);
}
<div class="thumb">
	  <a href="#"></a>
</div>