使图像与跨度文本重叠

时间:2017-12-12 14:31:59

标签: html css html5 css3

rawValue超过hover时,HERE应居中。第二个问题是image文本应该消失(重叠),因为只有HERE应该显示。如何解决这两个问题?



image

.eee span {
	font-weight: 700;
	font-size:2em;
}

.ggg {
 color: yellow;
 background: red;
}

.hhh {
 text-align: center;
 color: #fff;
 background-color: black;
}

.hhh:hover {
 background-color: green;
 background-image: url(http://via.placeholder.com/60x60);
 background-repeat: no-repeat;
 text-align: center;
}




2 个答案:

答案 0 :(得分:1)

使用background-position:center将图像居中,color: rgba()隐藏文字

.eee span {
	font-weight: 700;
	font-size:2em;
}

.ggg {
 color: yellow;
 background: red;
}

.hhh {
 text-align: center;
 color: #fff;
 background-color: black;
}

.hhh:hover {
 background-color: green;
 background-image: url(http://via.placeholder.com/60x60);
 background-repeat: no-repeat;
 background-position:center;
 color:rgba(0,0,0,0);
}
<div class="eee"><div class="fff"><span class="ggg">?</span> 
    <span class="hhh">HERE</span>
</div>
</div>

答案 1 :(得分:0)

试试这个:

.eee span {
	font-weight: 700;
	font-size:2em;
}

.ggg {
 color: yellow;
 background: red;
}

.hhh {
 text-align: center;
 color: #fff;
 background-color: black;
}

.hhh:hover {
 background-color: green;
 background-image: url(http://via.placeholder.com/60x60);
 text-align: center;
 background-position:center;
 color:rgba(0,0,0,0);
}
<div class="eee"><div class="fff"><span class="ggg">?</span> 
<span class="hhh">HERE</span>
</div>
</div>