将鼠标悬停在按钮标签内的定位范围:如何更改边框颜色和指针?

时间:2019-03-25 09:49:26

标签: html css button hover

我有一些卡片,当用户将鼠标悬停在border-color标记内的pointer-events标记时,想要更改属性spanbutton

如果我使用a标签,这没问题,请参阅左侧的“第一张卡片”:

https://codepen.io/anon/pen/JzzEvj

但是,当使用PRG模式和formbutton来更改指针事件和悬停时的border-bottom颜色时,不适用于Firefox 。 (请参阅右侧的第二张卡片)

有什么想法在Firefox中解决此问题吗?

所需结果,请参见左侧的卡片:

  • 将鼠标悬停在图像上时,光标应处于pointer状态
  • 将鼠标悬停在卡片标题上时,光标应处于pointer状态
  • 悬停卡片标题时,卡片标题的border-bottom颜色应更改颜色

https://i.imgur.com/fdWhZ7Y.jpg

我在这个问题上花了很多时间,但只发现了这个解决方案https://codepen.io/anon/pen/PLLWxJ,它并不完全相同,因为

  • 将鼠标悬停在卡的任何部分时,卡标题的border-bottom颜色会更改。
  • 悬停时,卡中的
  • 所有部分都可点击。悬停图像或卡片标题时,光标状态应仅更改为pointer

a {
  text-decoration: none;
}

.product-cards-wrapper {
  background: #fff;
  padding: 64px 0;
}

.product-cards {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.product-card {
  border: 1px dotted #ccc;
  cursor: default;
  margin: 0 16px 32px;
  width: 250px;
  text-align: center;
}

.product-card-img-wrapper {
  align-items: center;
  cursor: pointer;
  display: flex;
  justify-content: center;
  height: 150px;
  line-height: 0;
  margin-bottom: 16px;
}

.product-card-heading {
  border-bottom: 1px solid #e5e5e5;
  color: #2bb3f0;
  display: inline;
  font-family: sans-serif;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.6;
  text-align: center;
  transition: border-color .2s;
}

.product-card-heading:hover {
  border-color: #2bb3f0;
  cursor: pointer;
}

.product-card-label {
  background: #fee5ad;
  border-radius: 99px;
  color: rgba(0, 0, 0, .54);
  cursor: text;
  font-family: sans-serif;
  font-size: 14px;
  font-weight: 600;
  margin-top: 4px;
  padding: 2px 10px;
}

.product-card>button {
  background: 0;
  border: 0;
  padding: 0;
  width: 100%;
}

.product-card-heading {
  border-bottom: 1px solid #e5e5e5;
  color: #2bb3f0;
  cursor: pointer;
  transition: border-color .2s;
}

.product-card button .product-card-img-wrapper,
.product-card button .product-card-heading {
  cursor: pointer;
}

.product-card button .product-card-heading:hover {
  border-color: #2bb3f0;
}

.product-card-labels {
  display: block;
  font-family: sans-serif;
}
<section class=product-cards-wrapper>
  <div class=product-cards>
    <a class=product-card href=#>
      <div class=product-card-img-wrapper>
        <img src=https://via.placeholder.com/160x150 alt="">
      </div>
      <div class=product-card-heading>First Card</div>
      <div class=product-card-labels><span class=product-card-label>Label</span></div>
    </a>
    <form class=product-card action=# method=post target=_blank>
      <button name=l value=123>
						<span class=product-card-img-wrapper>
							<img src=https://via.placeholder.com/120x150 alt="">
						</span>
						<span class=product-card-heading>Second Card</span>
						<span class=product-card-labels><span class=product-card-label>Label</span></span>
					</button>
    </form>
  </div>
</section>

1 个答案:

答案 0 :(得分:0)

这是6年的Firefox错误,已在Firefox 66中修复。

带有button标签的孩子现在确实对:hover做出了响应。 :)

相关问题