CSS3伪类nth-child结合transiton动画实现文字若影若现_html/css_WEB-ITnose
css3伪类nth-child结合transiton动画实现文字若影若现
收先创建一个div盒子,然后包裹在div中的有10个span标签每个span标签填上内容一次为A,B,C,D,E,F,G,H,I,,J
先看下效果图:
看HTML5代码:
- A
- B
- C
- D
- E
- F
- G
- H
- I
- J
接下来给div添加一些css样式:
- .box {
- background-image: linear-gradient(135deg, #723362, #9d223c);
- color: #fff;
- padding: 1em 0;
- text-align: center;
- font-weight: 300;
- text-transform: uppercase;
- letter-spacing: .4em;
- padding-left: .4em;
- font-size: 1.8em;
- margin-top: 2.5rem
- }
这里要说一点的就是linear-gradient(,,,)
共有三个参数,第一个参数表示线性渐变的方向,top 是从上到下、left 是从左到右,如果定义成 left top,那就是从左上角到右下角。这里定义的是一个角度135度,第二个和第三个参数分别是起点颜色和终点颜色。
然后背景角色设置为#9d223c
文字为白色,且居中显示,文字加粗显示,其中text-transform: uppercase表示的是文字只以大写字母开头进行旋转,其它的一些就不用多说了都是常见的一些属性什么内边距外边距啊字体大小啊等等。
下面才是真正进入主题部分:
来看下面代码:
- .box1 span {opacity: 0;transition: opacity 1300ms}
- .box:hover span {opacity: 1}
- .box span:nth-child(1) { transition-delay: 200ms }
- .box span:nth-child(2) { transition-delay: 1200ms }
- .box span:nth-child(3) { transition-delay: 800ms }
- .box span:nth-child(4) { transition-delay: 300ms }
- .box span:nth-child(5) { transition-delay: 700ms }
- .box span:nth-child(6) { transition-delay: 600ms }
- .box span:nth-child(7) { transition-delay: 400ms }
- .box span:nth-child(8) { transition-delay: 900ms }
- .box span:nth-child(9) { transition-delay: 700ms }
- .box span:nth-child(10) { transition-delay: 50ms }
在设置完div的css样式后首先我们要给div下的span元素里的内容进行隐藏或者把他透明化,opacity:0表示的就是透明如果给他的值设置为1的话那就是不透明,当然你也可以设置为0.5或者0.3等等,opacity的值是0到1之间。
初始化设置透明为0后,在我们鼠标划过span元素的时候需要让再显示所以需要把透明度改为1
transition动画过度效果具体使用方法请看http://www.00h5.com/thread-15-1-1.html
其中transition-delay是transition的最后一个属性表示动画过度何时开始
再来看:nth-child,伪类选择器。
那么什么又是伪类?
伪类请看http://www.00h5.com/thread-76-1-1.html在这里我们用:nth-child来依次选择的设置span元素内容效果过渡,设置每个span的出现以及消失时间来达到效果。
最终完整代码:
-
transition - .box {
- background-image: linear-gradient(135deg, #723362, #9d223c);
- color: #fff;
- padding: 1em 0;
- text-align: center;
- font-weight: 300;
- text-transform: uppercase;
- letter-spacing: .4em;
- padding-left: .4em;
- font-size: 1.8em;
- margin-top: 2.5rem
- }
- .box span {opacity: 0;transition: opacity 1300ms}
- .box span:nth-child(1) { transition-delay: 200ms }
- .box span:nth-child(2) { transition-delay: 1200ms }
- .box span:nth-child(3) { transition-delay: 800ms }
- .box span:nth-child(4) { transition-delay: 300ms }
- .box span:nth-child(5) { transition-delay: 700ms }
- .box span:nth-child(6) { transition-delay: 600ms }
- .box span:nth-child(7) { transition-delay: 400ms }
- .box span:nth-child(8) { transition-delay: 900ms }
- .box span:nth-child(9) { transition-delay: 700ms }
- .box span:nth-child(10) { transition-delay: 50ms }
- .box:hover span {opacity: 1}
-
- A
- B
- C
- D
- E
- F
- G
- H
- I
- J

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.
