html - 影响顶部的颜色过渡‽
问题描述
我正在使用 Firefox 52.9.0。
我正在尝试向页面添加跳过导航链接。目前,页面如下所示:
/* Accessibility */
/* Hide the skip to main content link unless it has focus */
body > a:first-child {
background: inherit;
position: fixed;
left: 0px;
top: -1em;
transition: top 2s ease-out;
}
body > a::first-child:not(:focus) {
}
body > a:first-child:focus {
top: 0px;
transition: top 0.1s ease-in;
}
<a href="#lorem">skip to main content</a>
<main id="lorem">
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum... can't remember the rest, sorry.</p>
<p>This CSS is mostly fine.</p>
</main>
(点击页面并按下Tab查看效果。)
这看起来很好,除了下降线和下划线是可见的。为了解决这个问题,我告诉浏览器将文本颜色更改为transparent
没有焦点时:
/* Accessibility */
/* Hide the skip to main content link unless it has focus */
body > a:first-child {
background: inherit;
position: fixed;
left: 0px;
top: -1em;
transition: top 2s ease-out;
transition: color 2s ease-out;
}
body > a:first-child:not(:focus) {
color: darkgoldenrod;
}
body > a:first-child:focus {
top: 0px;
transition: top 0.1s ease-in;
transition: color 0.1s linear;
}
<a href="#lorem">skip to main content</a>
<main id="lorem">
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum... can't remember the rest, sorry.</p>
<p>This CSS behaves strangely.</p>
</main>
(transparent
被替换了,darkgoldenrod
所以更容易看到效果。)
过渡有效,但由于color
某种原因,它停止了top
过渡!
为什么会这样,我该如何解决?
解决方案
您的第二个transition
声明删除而不是添加到第一个声明。这是工作中的级联。
您不能使用多个transition
声明附加地声明单独的转换;您需要将它们分组为一个声明,如下所示:
body > a:first-child:focus {
top: 0px;
transition: top 0.1s ease-in, color 0.1s linear;
}
推荐阅读
- c# - 如何使用流,生成 csv 文件,在 .NET Core 3.1 中使用 CsvHelper?
- c# - 如何在 C# 中使用 IGeometry (NetTopolgy) 创建圆并存储为 IGeometry 类型
- excel - excel - 从交替列中查找行中的最后一个非空白单元格
- flutter - 以组的形式显示发送者和接收者之间的消息列表,每个组标签对应于日期
- ejabberd - 为什么我总是收到“不存在的主机”错误?
- sqlite - 当我们已经有了 WHERE 子句时,HAVING 子句有什么用?
- java - 树形图是如何工作的?
- javascript - 从 AntDesign 中选择时停止传播
- python - 烧瓶框架中的 sqlalchemy.exc.OperationalError (No such coumn)
- oracle - Oracle REGEXP_SUBSTR 在有多个空格时按空格提取字符串