css设置图片平移的方法:1、通过“translate(x,y)”属性使元素在x轴和y轴方向同时移动;2、通过“translate X(x)”属性使元素仅在x轴方向移动;3、通过“translateY(y)”属性使元素仅在y轴方向移动即可。
本教程操作环境:windows7系统、HTML5&&CSS3版本、Dell G3电脑。
推荐:css视频教程
平移的定义:元素在原来的位置上直线移动。
在CSS中,可以给img图片元素使用Transform属性来设置图片平移。
立即学习“前端免费学习笔记(深入)”;
Transform属性应用于元素的2D或3D转换。这个属性允许你将元素旋转,缩放,移动,倾斜等。
平移有三种情况:
translate(x,y)在x轴和y轴方向同时移动
translate X(x)仅在x轴方向移动
translateY(y)仅在y轴方向移动
示例:
nbsp;html>平移 *, *:after, *:before { box-sizing: border-box;}body { background: #F5F3F4; margin: 0; padding: 10px; font-family: 'Open Sans', sans-serif; text-align: center;}.card { display: inline-block; margin: 10px; background: #fff; padding: 15px; min-width: 200px; box-shadow: 0 3px 5px #ddd; color: #555;}.card .box { width: 100px; height: 100px; margin: auto; background: #ddd; cursor: pointer; box-shadow: 0 0 5px #ccc inset;}.card .box .fill { width: 100px; height: 100px; position: relative; background: #03A9F4; opacity: .5; box-shadow: 0 0 5px #ccc; -webkit-transition: 0.3s; transition: 0.3s;}.card p { margin: 25px 0 0;}.translate:hover .fill { -webkit-transform: translate(45px, 1em); transform: translate(45px, 1em);}.translateX:hover .fill { -webkit-transform: translateX(45px); transform: translateX(45px);}.translateY:hover .fill { -webkit-transform: translateY(45px); transform: translateY(45px);}translate(45px)
translateX(45px)
translateY(45px)
登录后复制
效果图:
更多编程相关知识,请访问:css视频教程!!
以上就是css如何设置图片平移的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2881354.html