HTML代码:
<div class="button"> <div class="hotzone"></div> <button>点击我</button> </div>
CSS代码:
.button {
position: relative;
}
.hotzone {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
z-index: 1;
}
.button:hover .hotzone {
opacity: 0.5;
}
.button:hover button {
color: #fff;
background-color: #f00;
border-color: #f00;
z-index: 2;
}
以上代码中,“.button”类定义了按钮的基本样式,“.hotzone”类定义了热区的样式,并设置了透明度为0,在鼠标移动到按钮上时透明度变为0.5。当鼠标移动到按钮上时,按钮的文本颜色、背景颜色和边框颜色也会发生变化。

