When elements have a specified position, such as fixed or relative, the CSS offset properties rightlefttop, and bottom can be used in animation rules to create movement.

As shown in the example below, you can push the item downwards then upwards by setting the top property of the 50% keyframe to 50px, but having it set to 0px for the first (0%) and the last (100%) keyframe.

 @keyframes rainbow {
0% {
background-color: blue;
top: 0px;
}
50% {
background-color: green;
top: 50px;
}
100% {
background-color: yellow;
top: 0px;
}
}

练习题目:

Add a horizontal motion to the div animation.

Using the left offset property, add to the @keyframes rule so rainbow starts at 0 pixels at 0%, moves to 25 pixels at 50%, and ends at -25 pixels at 100%.

Don't replace the top property in the editor - the animation should have both vertical and horizontal motion.

原本代码是上下移动,加上左右移动

练习代码:

 <style>
div {
height: 40px;
width: 70%;
background: black;
margin: 50px auto;
border-radius: 5px;
position: relative;
} #rect {
animation-name: rainbow;
animation-duration: 4s;
} @keyframes rainbow {
0% {
background-color: blue;
top: 0px;
left: 0px;
}
50% {
background-color: green;
top: 50px;
left: 25px;
}
100% {
background-color: yellow;
top: 0px;
left: -25px;
}
}
</style> <div id="rect"></div>

效果:

靠想象吧,动图我不会弄上来

一个上下左右移动的框子,带点颜色

FCC---Create Movement Using CSS Animation---设计一个盒子上下左右移动,结合animation, @keyframe, position (上下左右的offset)的更多相关文章

  1. Css中实现一个盒子固定宽度,另一个盒子宽度自适应的方法

    Css中实现一个盒子固定宽度,另一个盒子宽度自适应的方法 网上方法很多,个人认为以下两种思想是最为常用的. 一种是让第一个盒子脱离文档流,第二个盒子离左边有一定距离. 第二种方法是使用flex布局,不 ...

  2. CSS+DIV 设计一个简单的个人网页界面

    *{ margin:0px; padding:0px; } body{ background:#e5e6d0; } #header,#menu,#banner,#main,#footer{ margi ...

  3. No.6 - 利用 CSS animation 制作一个炫酷的 Slider

    *{ margin:; padding:; } div{ margin: auto; width: 800px; height: 681px; position: relative; overflow ...

  4. 百度前端技术学院2018笔记 之 利用 CSS animation 制作一个炫酷的 Slider

    前言 题目地址 利用 CSS animation 制作一个炫酷的 Slider 思路整理 首先页面包含三种东西 一个是type为radio的input其实就是单选框 二是每个单选框对应的label 三 ...

  5. 字符串混淆技术应用 设计一个字符串混淆程序 可混淆.NET程序集中的字符串

    关于字符串的研究,目前已经有两篇. 原理篇:字符串混淆技术在.NET程序保护中的应用及如何解密被混淆的字符串  实践篇:字符串反混淆实战 Dotfuscator 4.9 字符串加密技术应对策略 今天来 ...

  6. PS网页设计教程XXIV——从头设计一个漂亮的网站

    作为编码者,美工基础是偏弱的.我们可以参考一些成熟的网页PS教程,提高自身的设计能力.套用一句话,“熟读唐诗三百首,不会作诗也会吟”. 本系列的教程来源于网上的PS教程,都是国外的,全英文的.本人尝试 ...

  7. 如何去设计一个自适应的网页设计或HTMl5

    如何去设计一个自适应的网页设计或HTMl5 如今移动互联网随着3G的普及,越来越火爆,更多需求跟随而来!APP应用市场和APP应用数量成倍成倍的增长!从而给移动互联网带来新的挑战! 移动设备正超过桌面 ...

  8. bootstrap学习总结-css样式设计(一)

    由于项目需要,所以打算好好学习下bootstrap框架,之前了解一点,框架总体不难,但涉及到的东西还是很多,想要熟练掌握它,还是要多练练. 一:bootstrap是什么? bs是什么?  即前端页面搭 ...

  9. css笔记——区分css3中的transform transition animation

    出处:http://blog.csdn.net/dyllove98/article/details/8957232   CSS3中和动画有关的属性有三个  transform. transition  ...

随机推荐

  1. 在 Linux 下学习 C 语言有什么好处?

    作者:宅学部落链接:https://www.zhihu.com/question/23893390/answer/832610610来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...

  2. 分析Jackson的安全漏洞CVE-2019-12086

    CVE-2019-12086 Description A Polymorphic Typing issue was discovered in FasterXML jackson-databind 2 ...

  3. CAD转DXF怎么转换?教你三种转换方法

    CAD图纸在我们日常生活中都是可见到的,因为CAD图纸文件的格式是多样的,在工作中就需要经常将CAD的格式进行转换.那CAD转DXF怎么转换呢?这个问题很多的小伙伴们都遇到过,下面小编就来教大家三种转 ...

  4. 【C#】学习笔记 abstract、virtual、interface使用的一些栗子

  5. kotlinx.android.synthetic.** 坑点

    Kotlin通过添加 apply plugin: 'kotlin-android-extensions' 可以直接使用layout id 名称获取当前view对象,详细使用如下: //layout & ...

  6. HTML技巧篇:实现元素水平与垂直居中的几种方式

    如何使用html+css实现元素的水平与垂直居中效果,这也是我们网页在编码制作中会经常用到的问题. 1)单行文本的居中 主要实现css代码: 水平居中:text-align:center;垂直居中:l ...

  7. [Go] go连接influxdb的库

    开启了influxdb后,会监听8086端口下载客户端代码git clone https://github.com/influxdata/influxdb1-client.git $GOPATH/sr ...

  8. August 04th, 2019. Week 32nd, Sunday

    Making peace with what you don't have, that's what it's all about. 人生在世,不如意者十之八九,保持平常心,命里无时莫强求. Ever ...

  9. <Stack> (高频)394 ( 高频)224

    394. Decode String 四种情况: 1. 数字,把之前有的数字乘以10再加本数字 2. ' [ ', 入口, 把之前的数字压入栈中并num归零. 3. ' ] ' ,出口,归零.用dfs ...

  10. luogu5823 课表的排列

    题目链接 problem 构造一个长度为\(2n\)的数列.满足: 1.[1,n]中每个数字恰好出现两次. 2.将所有相同数字之间相隔的数字个数排序后,得到公差为1的等差数列. 保证n为奇数. sol ...