目标 CSS 转换为 pseudo-element "Arrow"?

Target CSS transition at pseudo-element "Arrow"?

我有一个 DIV,底部有一个 "arrow",就像漫画书中的对话泡泡一样,在悬停状态下出现:

箭头是使用 :after:before 伪元素创建的。

我有一个边框颜色和框阴影的悬停过渡。

我的问题是 "arrow" 只是 "appears"。没有像其他项目那样褪色,但我不知道如何定位 "arrow"。 "All" 看起来也不对。

理想情况下,我希望对箭头进行延迟并进行简单的淡入淡出或擦除。

这是CSS:

.item-selector-button {
  position: relative;
  text-align: center;
  cursor: pointer;
  border: 1px solid #cecece;
  padding: 15px;
  border-radius: 0;
  color: #000;
  width: 160px;
  height: 120px;
  transition: all ease-in-out 0.1s, box-shadow ease-in-out 0.1s;
}

.item-selector-button .title {
  color: #3e53a4;
  font-size: 12px;
  margin: 0;
  padding-top: -3px;
  font-family: "PrecisionSans_W_Md", "Helvetica Neue", Arial, sans-serif;
}

.item-selector-button .divider {
  height: 1px;
  width: 20px;
  background-color: #cecece;
  margin: 4px auto 10px;
}

.item-selector-button .image {
  background: #fff url("../images/box.png") center center no-repeat;
  width: 64px;
  height: 57px;
  margin: 4px auto;
}

.item-selector-button:hover, .item-selector-button.hover {
  padding: 14px;
}

.item-selector-button:hover:after, .item-selector-button.hover:after {
  content: "";
  position: absolute;
  bottom: -12px;
  left: 68px;
  border-width: 12px 12px 0;
  border-style: solid;
  border-color: #fff transparent;
  transition-delay: 0.3s;
}

.item-selector-button:hover:before, .item-selector-button.hover:before {
  content: "";
  position: absolute;
  bottom: -15px;
  left: 65px;
  border-width: 15px 15px 0;
  border-style: solid;
  border-color: #3e53a4 transparent;
  transition-delay: 0.3s;
}

.item-selector-button:active, .item-selector-button.active {
  border-width: 2px;
  border-color: #3e53a4;
  background-color: #3e53a4;
}

.item-selector-button:active:before, .item-selector-button.active:before {
  content: "";
  position: absolute;
  bottom: -15px;
  left: 65px;
  border-width: 15px 15px 0;
  border-style: solid;
  border-color: #3e53a4 transparent;
  transition-delay: 0.3s;
}

.item-selector-button:active .title, .item-selector-button.active .title {
  color: #fff;
}

.item-selector-button:active .divider, .item-selector-button.active .divider {
  background-color: #fff;
}

.item-selector-button:active .image, .item-selector-button.active .image {
  background-color: #3e53a4;
}

.item-selector-button:active:hover, .item-selector-button.active:hover {
  padding: 15px;
  box-shadow: none;
}

.item-selector-button:active:hover:after, .item-selector-button.active:hover:after {
  content: "";
  position: absolute;
  bottom: -12px;
  left: 68px;
  border-width: 12px 12px 0;
  border-style: solid;
  border-color: #3e53a4 transparent;
  transition-delay: 0.3s;
}

.item-selector-button.disabled {
  pointer-events: none;
  cursor: not-allowed;
}

.item-selector-button.disabled .title {
  color: #c3c3c3;
}

.item-selector-button.disabled .image {
  background-image: url("../images/box-disabled.png");
}

.item-selector-button.disabled:hover {
  padding: 15px;
  border: 1px solid #cecece;
  box-shadow: none;
}

悬停元素上只有伪元素,所以没有什么可以过渡的from/to。您需要在非悬停状态元素上添加伪元素。

转换可见性示例:

.item-selector-button:before {
    .arrow-inside(...);
    transition:all 5s ease;
    transition-delay: 0.3s;    
    visibility:hidden;
}

.item-selector-button:after {
    .arrow-outside(...);
    transition:all 5s ease;
    transition-delay: 0.3s;    
    visibility:hidden;
}

.item-selector-button:hover:before {
    visibility:visible;
}

.item-selector-button:hover:after {
    visibility:visible;
}