【问题标题】:arrow hover adding a circle div behind箭头悬停在后面添加一个圆形 div
【发布时间】:2021-02-19 22:28:01
【问题描述】:

我有两个箭头图像(上一个/下一个),代码如下:

.fp-controlArrow {
    position: absolute;
    width: 32px; /* This can be added here so you don't have to set a width and height 2 times for each arrow, this will create one width for both arrows */
    height: 32px; /* This does the same as above */
    margin-top:-15px; /* This value must always be half of the height - This does the same as above */
    z-index: 30;
    top: 50%;
    cursor: pointer;
}

.fp-controlArrow.fp-prev {
    left:0;
    background: url(https://uploads-ssl.webflow.com/602dbecd2160ce28b5bc428b/602e923133f8dc0bf994fc49_left-arrow.svg) no-repeat;
}
.fp-controlArrow.fp-next {
    right:0;
    background: url(https://uploads-ssl.webflow.com/602dbecd2160ce28b5bc428b/602e9231ec03b6c9682b540c_right-arrow.svg) no-repeat;

我希望当我将鼠标悬停在箭头上时,箭头后面会出现一个圆形透明圆圈,就像这个例子一样:

enter image description here

我怎样才能做到这一点?

谢谢!

【问题讨论】:

    标签: html css hover


    【解决方案1】:
    padding: 1em;
    border-radius: 50%;
    background-color: rgba(200,200,200,0.5)
    

    将这些行添加到 .fp-controlArrow 类中应该这样做。

    编辑

    抱歉,我没有意识到它是 svg。您必须内联 svg。

    <div class="fp-controlArrow fp-prev">
    
      <svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" data-reactroot="">
        <path stroke-linejoin="round" stroke-linecap="round" stroke-width="1" stroke="#221b38" d="M16 20L8 12L16 4"></path>
      </svg>
    
    </div>
    <div class="fp-controlArrow fp-next">
    
      <svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" data-reactroot="">
        <path stroke-linejoin="round" stroke-linecap="round" stroke-width="1" stroke="#221b38" d="M8 20L16 12L8 4"></path>
      </svg>
    
    </div>
    
    .fp-controlArrow {
        position: absolute;
        width: 32px; /* This can be added here so you don't have to set a width and height 2 times for each arrow, this will create one width for both arrows */
        height: 32px; /* This does the same as above */
        margin-top:-15px; /* This value must always be half of the height - This does the same as above */
        z-index: 30;
        top: 50%;
        cursor: pointer;
        padding: 1em;
        border-radius: 50%;
    
    }
    
    .fp-controlArrow:hover {
      background: green;
      background-color: rgba(200,200,200,0.5);
    } 
    
    .fp-controlArrow.fp-prev {
        left:0;
    }
    .fp-controlArrow.fp-next {
        right:0;
      
    

    这是一个演示它的codepen

    【讨论】:

    • 嗨,你试过这个吗?我无法让它工作,我想是因为图像是 SVG,但也许我做错了什么。
    【解决方案2】:

    抱歉,我没有看到 : 和 hover 之间的空格。

    .fp-controlArrow.fp-prev {
    left:0;
    background: url(https://uploads-ssl.webflow.com/602dbecd2160ce28b5bc428b/602e923133f8dc0bf994fc49_left-arrow.svg) no-repeat;
    border-radius: 50px;
    }
    .fp-controlArrow.fp-prev:hover{
    background-color: #999999;
    }
    

    【讨论】:

    • 我认为这行不通 - 背景图片是 svgs。
    • 抱歉,我试过你的代码,但它没有用,但现在我看到 : 和你的代码中的悬停之间有一个空格,我没有注意到。如果删除它就可以了。也许你可以把它编辑掉?
    • 我实际上尝试了您的代码,但没有发现 svg 文件有任何问题。此外,您已经在 svg 中添加了“不重复”,因此无需担心。
    猜你喜欢
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 2011-02-21
    • 1970-01-01
    相关资源
    最近更新 更多