有人能帮我复制Mahindra号公路上的动画红线吗?

我试过使用css,但它不起作用.

我已经复制了现有的css,但我没有运气,这似乎是一个如此简单的事情,但我不能让它工作.

Edit:我已经让它工作了,但只有在悬停时,有没有办法自动做它?

以下是我的代码:

.content {
    position: absolute;
    width: 60%;
    left: calc(5% + 0.75rem);
    transform: translate(0, 0%);
    top: 20%;
    color: #000;
    z-index: 2;
}

.content:before {
    content: "";
    display: block;
    position: absolute;
    width: 120px;
    height: 8px;
    background: #dd052b;
    left: 0;
    top: 50px;
    transform: rotate(-20deg) skew(-20deg) translate(-120%, 0);
    clip-path: inset(0 100% 0 0);
}

.content:after {
    content: "";
    display: block;
    position: absolute;
    width: 120px;
    height: 8px;
    background: #dd052b;
    left: 0;
    bottom: auto;
    top: 50px;
    transform: rotate(-20deg) skew(-20deg) translate(200%, 0%);
    clip-path: inset(0 100% 0 0);
}

.content:hover:after {
    clip-path: inset(0 0% 0 0);
    transition: all 0.6s linear;
    transition-delay: 1s;
}

.content:hover:before {
    clip-path: inset(0 0% 0 0);
    transition: all 0.6s linear;
    transition-delay: 0s;
}
<div class="content text-center text-lg-start active">
    <small style="transform: translate3d(0px, 0px, 0px); opacity: 1; visibility: inherit;">ABOUT US</small>
    <h1 class="heading font-medium font-size-tb" style="transform: translate3d(0px, 0px, 0px); opacity: 1; visibility: inherit;">Planet, People, Trust</h1>
    <p style="transform: translate3d(0px, 0px, 0px); opacity: 1; visibility: inherit;">Committed to drive positive change across global markets and communities.</p>
</div>

推荐答案

基本上,你得到了::after::before,而你在:hover上超过了他们.既然你希望它是"自动的",你应该使用103.

我已经制作了一部动画.还添加了animation-delay: 750ms;属性,使::after在启动前等待750ms(因此::before将在1000ms下工作,750ms之后::after将启动).我还添加了opacity: 0;::after以在显示::before时将其隐藏,并在动画结束时将其更改为1,以及我添加了animation-fill-mode: forwards;以保持::after的最后状态.

此外,我还删除了许多不需要的东西(除非您将它们用于其他目的),所以下面是最终代码:

.content {
    position: absolute;
    width: 60%;
    left: calc(5% + 0.75rem);
    transform: translate(0, 0%);
    top: 20%;
}

@keyframes animation {
    0% {
        clip-path: inset(0 100% 0 0);
    }
    100% {
        clip-path: inset(0 0% 0 0);
        opacity: 1;
    }
}

.content:before {
    content: "";
    position: absolute;
    width: 120px;
    height: 8px;
    background: #dd052b;
    top: 50px;
    animation: animation 1s;
    transform: rotate(-20deg) skew(-20deg) translate(-120%, 0);
}

.content:after {
    opacity: 0;
    content: "";
    position: fixed;
    width: 120px;
    height: 8px;
    background: #dd052b;
    top: 50px;
    animation: animation 1s;
    animation-delay: 750ms;
    animation-fill-mode: forwards;
    transform: rotate(-20deg) skew(-20deg) translate(200%, 0%);
}
<div class="content">
    <small>ABOUT US</small>
    <h1>Planet, People, Trust</h1>
    <p>Committed to drive positive change across global markets and communities.</p>
</div>

Css相关问答推荐

无法瞄准元素

如何为垫子制作圆角- Select 所有角点上的下拉列表

当面板以Angular 上升时如何定位下拉面板

靴子,为什么我不能让任何东西正确地排好队?

在最小和最大视口之间时具有固定值的 CSS 钳位

ReactJS 连续循环动画滚动

React MUI 从 CSS 伪元素中删除内容

动态覆盖 Vuetify 类

如何为 React Native switch 组件创建标签?

Tailwind css 和 Next.js 导航组件 z-index 不工作

css - 悬停访问的链接没有背景 colored颜色

带填充的水平边框

为什么标题中的特定 div 与 Odoo 13 中 PDF 中的页面重叠?

修复导航栏隐藏页面内容

在 IE9-10 中压缩 SVG 的背景大小

rotate3d 速记

在 Twitter Bootstrap 中创建圆角的正确方法

使用 CSS go 除图像之间的空间

@font-face src: local - 如果用户已经拥有本地字体,如何使用它?

通过 JavaScript 更改 CSS 伪元素样式