线性渐变和背景大小添加了这个很酷的效果,任何人都可以解释

用户2860957

如果这是个愚蠢的问题,我很抱歉,但是这段代码让我发疯了,我把它拆下来,以为我能够理解,但是在这样做并投入 2-4 小时之后,我现在对我所做的事情感到困惑以为我知道。下面的代码在我结束时添加了这个很酷的效果,看起来背景是从底部出现并到达顶部,只认为我知道它与背景图像、线性渐变、背景大小和背景位置有关

请看一看,试着让我摆脱痛苦。代码

<ul><li><a href="#" title="Home">Home</a></li> </ul>

css代码

li {
 background-image: 
  linear-gradient(to bottom, 
  transparent 50%, 
  #a2d39c 50%, #a2d39c 95%, #7cc576 95%);
  background-size: 100% 200%;
  transition: all .25s ease;
}
li:hover {
    background-position: bottom center;}

li a {display: block;
  padding: 1rem 0;}

如果任何机构想要链接,这里也是链接。

https://codepen.io/arif_suhail_123/pen/jLPYOB

富巴

我在下面注释了你的样式,希望能解释发生了什么。

li {
    // You're creating a background gradient, where the first 50% is transparent, the next 45% is #a2d39c and the last 5% is #7cc576
    background-image: 
        linear-gradient(to bottom, 
        transparent 50%, 
        #a2d39c 50%, #a2d39c 95%, #7cc576 95%);

    // The background size is twice the height of your element. Therefore with the 50% transparency and initial position, you're not going to see anything
    background-size: 100% 200%;

    // This will nicely transition between CSS property values when they change
    transition: all .25s ease;
}
li:hover {
    // When you hover over your list item, you're changing the position so that the bottom of the background is visible. This causes the 50% transparent portion of the background to disappear, and the coloured portion to slide into view
    background-position: bottom center;}
}

背景位置

如果您查看background-position的 CSS 规范,您会看到默认值是0% 0%,基本上是top left.

您的 CSS 代码未指定初始背景位置,因此默认为top left. 记住这一点。

您的背景渐变已定义to bottom,因此从top -> bottom. 前 50% 是transparent(不可见的)。第二个 50% 由两种不同的颜色组成。

然后考虑您的背景渐变是元素高度的两倍。这是由background-size: 100% 200%(100% 宽度,200% 高度)指定的。背景可以大于应用它的元素,并且任何溢出都将被隐藏。

所以最初当你只显示背景渐变的上半部分时,你会看到什么?只有transparent部分。

当您覆盖background-position悬停时,您是说现在显示该bottom center部分。看看你的背景如何与元素的全宽相匹配,center水平值不会改变任何东西。bottom垂直设置确实如此。现在意味着显示第二个 50%。

这有帮助吗?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

任何人都可以解释这个Javascript数据结构吗?

任何人都可以解释此HashMap行为

任何人都可以解释以下声明

任何人都可以逐步解释该过程

任何人都可以解释以下程序的输出

任何人都可以回答这个问题吗?

任何人都可以帮助我解决 Hibernate 和 JSF 的这个缺点吗?

我想添加一个参数以在angular中发布请求。任何人都可以解释

任何人都可以解释android中的未绑定和绑定服务有什么区别

任何人都可以向我解释dispatch_sync和dispatch_async之间的区别吗?

informatica-任何人都可以解释如何在输入数据上执行映射和转换

任何人都可以解释为什么这代码连接,而不是增加的数值?

java 任何人都可以解释这种类型的逻辑

任何人都可以通过示例详细解释多态关联吗?

任何人都可以对CURIE及其使用方法进行很好的解释吗?

任何人都可以在PHP中解释此数组声明-> $ a {0} =“ value”

任何人都可以在这段代码中解释我的打印语句吗?

任何人都可以解释待处理的意图及其参数

任何人都可以解释这意味着什么

任何人都可以请解释我对我的反应 setState new

关于pytorch张量的奇怪行为。任何人都可以解释清楚吗?

任何人都可以解释这种有关数组排序的奇怪行为吗?

任何人都可以向我解释ip =“ $ {ip:-$ {default_ip}}

任何人都可以向初学者解释什么是终端配置文件?

任何人都可以对以下javascript RE代码进行解释吗?

任何人都可以在HTML服务的GAS文档中解释用户对象示例吗?

任何人都可以在此代码中解释javax.swing.SwingUtilities.invokeLater的使用

任何人都可以解释这意味着什么

按钮组件中的 MUI 奇怪代码,希望任何人都可以解释