用css实现扑克牌,图片的翻转效果

话不多说,直接上代码!
1.实现商品图片的翻转以及信息的展示(下面代码仅是个人想要效果的HTML代码,所有的class名称可根据自身需求进行改动)

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title><style>body {text-align: center;}.pictrue-animation {width: 1200px;height: 120px;background: pink;margin: 5px auto;}.pictrue-animation > .img-show {width: 120px;height: 120px;background: orange;margin: 0 15px;float: left;}.img-show > .pictrue-mc {display: block;width: 120px;height: 100px;margin: 0;text-decoration: none;}.pictrue-mc .xx-show {width: 90px;height: 18.5px;background: pink;line-height: 18.5px;border-bottom: 2px solid green;margin: 0 auto;}/*-------------------------扑克牌效果------------------------------------------*//*-----------------------------pukepai----------------------*/p .pictrue-show {width: 120px;height: 80px;border: none;margin: 20px 0;}.img-show .xx-showbz {width: 120px;height: 20px;line-height: 20px;}.img-show .pictrue-mc .xx-show,.img-show .xx-showbz {background: purple;text-align: center;font-size: 12px;color: white;display: none;}.img-show:hover {margin: 0 15px;}.img-show:hover .pictrue-mc #wrap .pictrue-show {margin: 0;padding: 0;}.img-show:hover .xx-show,.img-show:hover .xx-showbz {display: block;}#wrap {width: 120px;height: 80px;margin: 20px 0;padding: 0;position: relative;perspective: 800px;}#box {width: 120px;height: 80px;margin: 0;padding: 0;position: absolute;left: 0;top: 0;transform-style:preserve-3d;}#box p {width: 120px;height: 80px;position: absolute;backface-visibility: hidden;top: -36px;left: 0;}#box p:nth-of-type(1) {transition:.8s transform;}#box p:nth-of-type(2) {transform:rotateY(-180deg);transition:.8s transform;}#box:hover p:nth-of-type(1) {transform:rotateY(180deg);}#box:hover p:nth-of-type(2) {transform:rotateY(0deg);}</style>
</head><body><div class="pictrue-animation"><div class="img-show"><a href="" class="pictrue-mc"><span class="xx-show">长城</span><div id="wrap"><div id="box"><p><img src="img/9.jpg" alt="" class="pictrue-show" /></p><p><img src="img/7.jpg" alt="" class="pictrue-show" /></p></div></div></a><span class="xx-showbz">你值得拥有!</span></div><div class="img-show"><a href="" class="pictrue-mc"><span class="xx-show">长城</span><div id="wrap"><div id="box"><p><img src="img/9.jpg" alt="" class="pictrue-show" /></p><p><img src="img/7.jpg" alt="" class="pictrue-show" /></p></div></div></a><span class="xx-showbz">你值得拥有!</span></div><div class="img-show"><a href="" class="pictrue-mc"><span class="xx-show">长城</span><div id="wrap"><div id="box"><p><img src="img/9.jpg" alt="" class="pictrue-show" /></p><p><img src="img/7.jpg" alt="" class="pictrue-show" /></p></div></div></a><span class="xx-showbz">你值得拥有!</span></div><div class="img-show"><a href="" class="pictrue-mc"><span class="xx-show">长城</span><div id="wrap"><div id="box"><p><img src="img/9.jpg" alt="" class="pictrue-show" /></p><p><img src="img/7.jpg" alt="" class="pictrue-show" /></p></div></div></a><span class="xx-showbz">你值得拥有!</span></div><div class="img-show"><a href="" class="pictrue-mc"><span class="xx-show">长城</span><div id="wrap"><div id="box"><p><img src="img/9.jpg" alt="" class="pictrue-show" /></p><p><img src="img/7.jpg" alt="" class="pictrue-show" /></p></div></div></a><span class="xx-showbz">你值得拥有!</span></div><div class="img-show"><a href="" class="pictrue-mc"><span class="xx-show">长城</span><div id="wrap"><div id="box"><p><img src="img/9.jpg" alt="" class="pictrue-show" /></p><p><img src="img/7.jpg" alt="" class="pictrue-show" /></p></div></div></a><span class="xx-showbz">你值得拥有!</span></div><div class="img-show"><a href="" class="pictrue-mc"><span class="xx-show">长城</span><div id="wrap"><div id="box"><p><img src="img/9.jpg" alt="" class="pictrue-show" /></p><p><img src="img/7.jpg" alt="" class="pictrue-show" /></p></div></div></a><span class="xx-showbz">你值得拥有!</span></div><div class="img-show"><a href="" class="pictrue-mc"><span class="xx-show">长城</span><div id="wrap"><div id="box"><p><img src="img/9.jpg" alt="" class="pictrue-show" /></p><p><img src="img/7.jpg" alt="" class="pictrue-show" /></p></div></div></a><span class="xx-showbz">你值得拥有!</span></div></div>
</body>
</html>

2.通用实现图片翻转(说明:该代码来自其他大佬的博客代码,有所改编)
css代码

<style>#wrap {width: 320px;height: 200px;margin: 0 auto;position: relative;perspective:800px;}#box {position: absolute;left: 0px;width: 320px;height: 200px;transform-style:preserve-3d;}#box p {width: 100%;height: 100%;position: absolute;left: 0px;top: -30px;font-size: 28px;backface-visibility: hidden;color: #fff;}#box p img {width: 320px;height: 200px;}#box p:nth-of-type(1) {transition:.8s transform;}#box p:nth-of-type(2) {transform:rotateY(-180deg);transition:.8s transform;}#box:hover p:nth-of-type(1) {transform:rotateY(180deg);}#box:hover p:nth-of-type(2) {transform:rotateY(0deg);}</style>

首先,想要实现翻转效果,需要对其进行层定位,先设置一个舞台(即最外面的那个盒子),一个小盒子中放置一个图片。对最外面的盒子进行相对定位position:relative;其他盒子进行绝对定位position:absolute;
该例子中的p元素也可置换成一个div盒子
其次,就是我们需要将第一个图片放置最上面,另一张图片作为其反面,同时第二张图片最开始就要翻转180度,原因就是里面的正面显示的图片翻转过来之后,会将原来的图片呈现相反的效果,所以我们需要将里面的图片在显示时,就将其翻转(具体可以看代码展示效果)
核心代码如下:
#box p:nth-of-type(1) {
transition:.8s transform;
}
#box p:nth-of-type(2) {
transform:rotateY(-180deg);
transition:.8s transform;
}
#box:hover p:nth-of-type(1) {
transform:rotateY(180deg);
}
#box:hover p:nth-of-type(2) {
transform:rotateY(0deg);
}
也就是将最靠近图片的那个盒子进行上述操作,nth-of-type() 应该是一个伪类元素,我也不是很了解,有兴趣的可以自己去探索,在这就不多说。
实现扑克牌翻转,我们需要3D动画效果,并且是沿着y轴去翻转。

 *html代码*

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>翻转</title>
</head>
<body><div id="wrap"><div id="box"><p><img src="../sheji/img/7.jpg" alt=""></p><p><img src="../sheji/img/9.jpg" alt=""></p></div></div></body>
</html>

图片自己寻找,大小一样ok,在这里的图片尺寸是320*200,
注意,当需要多个的时候,这里用class类型选择器id选择器要好,
因为id选择器是适合特例,特殊,优先级比class选择器要高
但是id选择器具有唯一性,不能使用多次,如果使用多次,DW会提示有错误。心得
总之,在困扰了我将近一周的时间,我终于找到了适合我的这些代码,希望对你们有帮助,一起学习,共同进步!
由于本人最近在练习如何写博客,有错误之处还请原谅。

用css实现扑克牌,图片的翻转效果相关推荐

  1. php图片滑动的属性,使用css怎么实现图片的滑动效果?(示例)

    本篇文章主要给大家介绍关于css实现图片的滑动效果示例,希望大家阅读完本篇后对css滑动效果的相关知识有所了解. 下面给大家举一个简单的css图片滑动效果示例(自下而上滑动): css怎么实现图片滑动 ...

  2. HTM+CSS实现立方体图片旋转展示效果

    目的:HTM+CSS实现立方体图片旋转展示效果 环境: 系统:Win10 环境: 一.示例1. 话不多说直接上代码 <html><head><style>/*立方体 ...

  3. html+css+js 实现图片轮播效果

    html+css+js 实现图片轮播效果 图片轮播效果: 会自动 向左 || 向右 切换图片 能手动点击按钮切换图片 多用于商品展览等等 --首先我们创建一个盒子进行展览,然后一个< ul> ...

  4. css鼠标悬停图片剪辑路径效果

    下载地址 一款css鼠标悬停图片剪辑路径效果,当鼠标悬停在图片上时,图片按一定路径放大的动画特效,生动形象,让图片灵活起来. dd:

  5. css鼠标经过图片镜像翻转,css代码实现鼠标指向图片翻转效果

    烈火网(Liehuo.Net)教程 今天有读者询问制作鼠标经过时切换图片的效果,这种效果也称为"翻转"效果(roll-over).原来这种效果大多使用Javascript实现,实际 ...

  6. CSS3之图片3D翻转效果(网页效果--每日一更)

    今天,带来的是纯CSS3的效果--图片3D翻转. 请看效果:亲,请点击这里 这个效果主要还是运用了CSS3的transform变形属性,与上个效果不同的是,这次并不是动画,所以没有采用animatio ...

  7. 图片3D翻转效果 --摘自李硕老师博客160305

    原文地址:http://blog.csdn.net/u012215170/article/details/50421023 ndroid手机上有众多的炫酷的设计风格,动画必然是APP的一大亮点,所以一 ...

  8. html3d上下翻转4面效果,花式实现图片3D翻转效果

    闲话 曾经在闲逛时,看到有一个很炫的3D翻转切换图片的效果.地址在这里:https://tympanus.net/Development/Slicebox/index.html 一直想搞一个,最近撸出 ...

  9. css背景图毛玻璃,css实现背景图片的毛玻璃效果

    问题一css 一.简述问题html 最近在作登陆页面的时候,遇到了一个问题:将登陆页面的背景图片,设置为毛玻璃效果.在网上找到了关于这方面的资料.web 二.问题解决svg .blur { filte ...

最新文章

  1. SSL/TLS原理详解
  2. day16-小数据池
  3. android代码设置全屏
  4. Js里面IF(var)表示什么意思?js中if的写法、含义
  5. C++可重载运算符和不可重载运算符
  6. Android自定义实现FlowLayout
  7. 运算、函数、数组的了解
  8. Alfresco支持LDAP验证
  9. 雅可比迭代c++实现_线性方程组(3)-静态迭代法
  10. aix服务器设备型号,IBM产品系列和AIX系统版本
  11. [引用]关于C#操作INI文件的总结
  12. 【Python成长之路】卡萨帝冰箱能买吗?让数据来说话!
  13. C语言结构体struct
  14. 万年历包括对应节日c语言,C语言 程序设 节日查询和任务提醒系统-万年历.doc
  15. 土地利用分类详细教程——以高分一号影像为例(上)
  16. 大数据到底应该如何学?
  17. 苹果浏览器Safari
  18. 解决mysql sum求和返回null问题或IFNULL应用
  19. IDM(Internet Download Manager)—下载各类安装包(github代码、python包)、软件、视频、文档的神器,居家必备良药...
  20. 小红书的文案有什么特点

热门文章

  1. div布局系列 - 两端对齐的方法
  2. 计算机团体及知名科学家,2019年度ACM杰出科学家!拿下华人数学领域最高荣誉的上财陆品燕教授,又拿奖啦!...
  3. EL表达式写三目运算
  4. 有限元方法基础-以二维拉普拉斯方程为例(附程序)
  5. vs哪个版本好用_【小巨人分享】VS出品销量神器 沛纳海 441 升级版来了!
  6. Android 操作系统基础
  7. 最全的日期年农历假日节气星座等计算类封装
  8. 浅谈HTTP缓存以及后端,前端如何具体实现HTTP缓存
  9. 剑指 Offer 05. 替换空格
  10. 低风险整体式微服务演进第一部分