css - 具有尖头的矩形,悬停时会改变颜色

标签 css

除了一件事,我在这个网站上找到了一个符合我需要的例子。如果我添加悬停,左右三 Angular 形将具有相同的颜色,而不是新的悬停颜色。知道当我们将鼠标悬停在矩形上时如何产生黑色三 Angular 形吗?

.yourButton {
    position: relative;
    width:200px;
    height:40px;
    margin-left:40px;
    color:#FFFFFF;
    background-color:blue;
    text-align:center;
    line-height:40px;
}
.yourButton:hover {background-color:black}
.yourButton:before {
    content:"";
    position: absolute;
    right: 100%;
    top:0px;
    width:0px;
    height:0px;
    border-top:20px solid transparent;
    border-right:40px solid blue;
    border-bottom:20px solid transparent;
}

.yourButton:after {
    content:"";
    position: absolute;
    left: 100%;
    top:0px;
    width:0px;
    height:0px;
    border-top:20px solid transparent;
    border-left:40px solid blue;
    border-bottom:20px solid transparent;
}
<div class="yourButton">You wanted this?</div>

最佳答案

您需要为 :after:before 制作 2 个不同的悬停类并更改边框颜色。

.yourButton {
    position: relative;
    width:200px;
    height:40px;
    margin-left:40px;
    color:#FFFFFF;
    background-color:blue;
    text-align:center;
    line-height:40px;
}
.yourButton:hover {background-color:black}
.yourButton:before {
    content:"";
    position: absolute;
    right: 100%;
    top:0px;
    width:0px;
    height:0px;
    border-top:20px solid transparent;
    border-right:40px solid blue;
    border-bottom:20px solid transparent;
}

.yourButton:after {
    content:"";
    position: absolute;
    left: 100%;
    top:0px;
    width:0px;
    height:0px;
    border-top:20px solid transparent;
    border-left:40px solid blue;
    border-bottom:20px solid transparent;
}


.yourButton:hover:after{
   border-left:40px solid #000;
}
.yourButton:hover:before{
  border-right:40px solid #000;
}
<div class="yourButton">You wanted this?</div>

关于css - 具有尖头的矩形,悬停时会改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33164302/

相关文章:

html - 如何删除表格中的水平线?

html - 如何在不激活水平滚动条的情况下将图像放置在包装器周围

html - 子菜单文本颜色无法在 Wordpress 站点中更改

html - CSS3 flexbox 布局一行最多 3 个子项

html - 如何在一行中显示三个文本字段

javascript - 中心/裁剪图像 - 使用 Cycle2 插件的响应式幻灯片

html - Font Awesome 图标不起作用,我已经包含了所有必需的文件

CSS3在没有javascript的情况下在滚动上执行动画

css - 带有 ng-model 范围变量的 AngularJS ng-style

html - 为显示为 :inline-block 的 div 元素设置中心位置