
新阅读器的完成
指的是firefox、chrome和IE9。新阅读器都撑持CSS3新添的transform属性,以是完成倒影结果很是简略。从下面的代码看到,各家阅读器对transform的完成有点不同
-webkit-transform: scaleY(-1); /* webkit内核阅读器的完成,比方safari */
-moz-transform: scaleY(-1); /* firefox 的完成 */
-ms-transform: scaleY(-1); /* IE 的完成 */
-o-transform: scaleY(-1); /* Opera的完成 */
<div class="wrap"> <div class="image"><img src="1.jpg" /></div> <div class="down"> <div class="reflection"></div> <div class="overlay"></div> </div> </div>
body{background:#000;color:#f00} .wrap{position:relative;} .image{margin-bottom:3px;} .down{position: relative;} .reflection{width:421px;height:180px;background:url(1.jpg) bottom center no-repeat; -webkit-transform: scaleY(-1); -moz-transform: scaleY(-1); -ms-transform: scaleY(-1); -o-transform: scaleY(-1); transform: scaleY(-1); opacity:0.5; filter:alpha(opacity='50'); } .overlay{position: relative;width:421px;height:180px;bottom:149px; background-image: -moz-linear-gradient(center bottom, rgb(0,0,0) 20%, rgba(0,0,0,0) 90%); background-image: -o-linear-gradient(rgba(0,0,0,0) 10%, rgb(0,0,0) 30%); background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.20, rgb(0,0,0)), color-stop(0.90, rgba(0,0,0,0))); filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColor=0, EndColorStr=#000000); }
在倒转的图片下面还加了一个DIV.overlay层,做出突变的结果,使倒影看起来更实在。
兼容旧阅读器的完成
斟酌到另有相称多的人在利用旧版阅读器,法式员挖空心思为这局部人做兼容。这里指的是IE7/IE8。IE6怎样办?提醒用户进级阅读器吧。
旧IE不撑持transform属性,能够利用滤镜 filter:flipv 来天生图片倒转,但会跟IE9的transform抵触。以是要用到各类 hack 来处理。点窜后的CSS以下,增加了IE9 hack,笼盖掉下面的filter:flipv的属性。
body{background:#000;color:#f00} .wrap{position:relative;} .image{margin-bottom:3px;} .down{position: relative;} .reflection{width:421px;height:180px;background:url(1.jpg) bottom center no-repeat; -webkit-transform: scaleY(-1); -moz-transform: scaleY(-1); -ms-transform: scaleY(-1); -o-transform: scaleY(-1); transform: scaleY(-1); opacity:0.5; filter:flipv alpha(opacity='50'); /*ALL IE*/ } @media all and (min-width:0) { .reflection{filter:alpha(opacity='50') \0/;} /*IE9*/ } .overlay{position: relative;width:421px;height:180px;bottom:149px; background-image: -moz-linear-gradient(center bottom, rgb(0,0,0) 20%, rgba(0,0,0,0) 90%); background-image: -o-linear-gradient(rgba(0,0,0,0) 10%, rgb(0,0,0) 30%); background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.20, rgb(0,0,0)), color-stop(0.90, rgba(0,0,0,0))); filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColor=0, EndColorStr=#000000); }