我在网页上有一个 HTML 按钮,其中的文本在悬停时变为粗体。但是,当这种情况发生时,按钮会变大,我不想发生这种情况。因此,我使用了一些简单的 JavaScript 使按钮在 document.ready 时的大小为 150%。但是,我试图尽量减少对 JS 的使用,那么这可能仅在 CSS 中实现吗?
代码示例:
<button id="b1">Test</button>
<style>
<!-- When you hover over the button, it resizes - I want the width to become 150% what it would be on page load. -->
#b1{
float: right;
margin-left: 15px;
background-color: white;
height: 100%;
transition-duration: 0.2s;
font-weight: bold;
border: 0;
font-size: 20px;
outline: 0;
}
#b1:hover{
color: #33F;
font-size: 22px;
}
</style>
提前致谢,
- 马修