《 CSS Secrets 》是 @Lea Verou 最新著作,这本书讲解了有关于CSS中一些小秘密。是一本CSSer值得一读的一本书,经过一段时间的阅读,我、@南北和@彦子一起将在W3cplus发布一系列相关的读后感,与大家一起分享。
问题
您还记得
然而,让人讨厌的
一个常见的用户体验模式是闪烁几次(不超过三次),改变已应用的UI或强调当前链接目标。用一个这样有限制的闪烁效果可以有效的吸引用户的注意力,但由于数量的有效控制,它没有
然而,我们该如何实现呢?仅使用CSS来替代
解决方案
实际上使用CSS有多种方式可以实现任何一种闪烁效果:整个元素( opacity )、文本颜色( color )、边框( border-color )等等闪乐。在接下来的内容,我们假设要实现一个闪烁的文本效果,因为这个效果是最常见的。但是其他部分的解决方案与这个示例是类似的。
实现平滑的闪烁效果相当容易。我们开头提出的总是,可以像下面这样巧妙的处理:
@keyframes blink-smooth { to { color: transparent } }.highlight { animation: 1s blink-smooth 3; }
这个效果几乎是正常的,文本从文本颜色顺利的变成透明,但是突然跳回到原来的文本色。我们可以通过下图来帮助我们弄清楚文本颜色随着时间的推移发生的变化,弄清楚为什么会发生这种情况:
实际上这样做是可取的。在这种情况下,我们完成了需要的效果。然而,当我们需要让文本逐渐消失有一个平滑的闪烁,还有更多的事情要做。要实现这一目标的途径之是是通过改变关键帧来转换每个迭代中发生的事情。
@keyframes blink-smooth { 50% { color: transparent } }.highlight { animation: 1s blink-smooth 3;}
这看起来像我们想要的结果。然而,尽管颜色的变化不能在动画中显示(因为很难区分时间函数进展时颜色,不透明的具体转变),重要的是记住,动画都是加速的,这可能对于某些动画看起来不自然(比如,pulsating动画)。在这种情况下,我们可以把工具拿出来,处理 animation-direction 。
animation-direction 唯一目的是用来设置动画的方向。他的作用是,动画播放在第偶数次向前播放,第奇数次向反方向播放。这个功能是很强大的,可以实现更为逼真的动画。我们可以尝试在闪烁的动画中使用这个,如下:
@keyframes blink-smooth { to { color: transparent } }.highlight { animation: .5s blink-smooth 6 alternate;}
请注意,我们迭代的次数必须是二的倍数,就如"fade-in"和"fade-out"这样成对出现一样。出于同样的原因,我们的 animation-duration 时间也得减半。
anmiation-direction 有四个值,颜色从 black 过渡到 transparent 发生三次迭代。
如果我们想要顺利的实现平滑的闪烁动画效果,我们就要在这一点上想法子。那我们得怎么做呢?大家一起来尝试尝试吧:
@keyframes blink { to { color: transparent } }.highlight { animation: 1s blink 3 steps(1);}
然而,你没看到他有任何变化,因为它失败了。主要原因是 steps(1) 本质上相当于 steps(1,end) ,这也意味着,当前文本颜色过渡到透明色就在第一步中发生,并且结束。如下图所示:
因此,我们看到的动画的长度值就是一个短暂的时间点。如果改为 steps(1,start) 会发生相反的,一开始看到的就是透明的文本,没有动画或闪烁。
逻辑上下一步应该设置 steps(2) ,设置开始和结束。现在我们可以看到一些闪烁的效果,但在半透明的文本和透明或透明和正常的分别。不幸运的是,我们不能通过 steps() 设置中间值,只能设置开始和结束,唯一的解决办法就是调整动画的关键帧,将其设置为 50% ,如下所示:
@keyframes blink { 50% { color: transparent } }.highlight { animation: 1s blink 3 steps(1); /* or step-end */}

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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