转换不在悬停上工作

时间:2018-03-26 12:13:27

标签: css hover transition mousehover

我不知道但由于某些原因,过渡似乎并没有奏效。我正在测试此Google Chrome。



[data-title] {
	position: relative;
  margin: 100px;
}

[data-title]:hover:before {
  transform: translate(-50%, 0);
	width: 18px;
	height: 6px;
	left: 50%;
	margin-top: 0px;
	top: 100%;
	opacity: 1;
	pointer-events: auto;
  -webkit-transition: all 0.25s;
  transition: all 0.25s;
	content: '';
	position: absolute;
	z-index: 10;
	box-sizing: border-box;
	border-left: 8px solid transparent;
	border-right: 8px solid transparent;
	border-bottom: 10px solid #00204e;
  
}

[data-title]:hover:after {
	transform: translate(-50%, 0);
	left: calc(50%);
	margin-top: 10px;
	top: 100%;
	opacity: 1;
	pointer-events: auto;
  -webkit-transition: all 0.25s;
  transition: all 0.25s;
	font-weight: normal;
	text-shadow: none;
	background: #00204e;
	border-radius: 4px;
	color: #fff;
	content: attr(data-title);
	padding: 10px;
	position: absolute;
	white-space: normal;
	width: max-content;
	font-size: 12px;
	font-family: 'Helvetica Neue';
	line-height: normal;
	max-width: 150px;
	text-align: left;
	height: auto;
	display: inline-block;
}

<span class="dijitButtonContents" id="saveButton" data-title="Save as draft"><span id="saveButton_label">Save</span></span>
&#13;
&#13;
&#13;

任何人都可以帮助我出错或者我错过了什么吗?

我甚至尝试将转换时间设为+1秒,但它仍然没有反映出相同的时间。

2 个答案:

答案 0 :(得分:4)

您没有为原始状态设置任何内容,因此转换不知道该怎么做。如果你只是想要转换项目的外观 - 例如淡入或淡出,那么你需要做一些像过渡不透明度的事情:

[data-title] {
  position: relative;
  margin: 100px;
}

[data-title]:before {
  width: 18px;
  height: 6px;
  left: 50%;
  margin-top: 0px;
  top: 100%;
  opacity: 1;
  content: '';
  position: absolute;
  z-index: 10;
  box-sizing: border-box;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 10px solid #00204e;
  transform: translate(-50%, 0);
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
}

[data-title]:after {
  transform: translate(-50%, 0);
  left: calc(50%);
  margin-top: 10px;
  top: 100%;
  opacity: 1;
  font-weight: normal;
  text-shadow: none;
  background: #00204e;
  border-radius: 4px;
  color: #fff;
  content: attr(data-title);
  padding: 10px;
  position: absolute;
  white-space: normal;
  width: max-content;
  font-size: 12px;
  font-family: 'Helvetica Neue';
  line-height: normal;
  max-width: 150px;
  text-align: left;
  height: auto;
  display: inline-block;
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
}

[data-title]:hover:before,
[data-title]:hover:after {
  opacity: 1;
  pointer-events: auto;
}
<span class="dijitButtonContents" id="saveButton" data-title="Save as draft"><span id="saveButton_label">Save</span></span>

答案 1 :(得分:0)

如果你想从一个州到另一个州transition,你必须定义这两种状态。这意味着具有基本风格和:hover风格。

例如:

.test {
  width: 100px;
  height: 50px;
  background: red;
  transition: all 2s;
}

.test:hover {
  height: 100px;
}
<div class="test">test</div>

这是有效的,因为height属性有一个初始状态。但是:

.test {
  width: 100px;
  background: red;
  transition: all 2s;
}

.test:hover {
  height: 300px;
}
<div class="test">test</div>

这不起作用,因为浏览器没有指定的height作为初始状态。