2

我在网页上有一个 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>

提前致谢,

- 马修

4

1 回答 1

2

  .btn1{
	background:#0095ff;
	border:0;
	outline:0;
	font-weight:400;
	color:#fff;
	font-size: 16px;
	padding: 6px 15px;
	transition: all .4s ease;
	cursor:pointer;
	text-transform:uppercase;
    }
    .btn1:hover{ 
	font-weight:600;
        background:#07c;
    }


    .btn2{
	background:#0095ff;
	border:0;
	outline:0;
	font-weight:400;
	color:#fff;
	font-size: 16px;
	padding: 6px 15px;
	transition: all .4s ease;
	cursor:pointer;
	text-transform:uppercase;
	min-width:150px;
    }
   .btn2:hover{ 
	font-weight:600;
	background:#07c;
    }
    This might be the Problem :
    <button class="btn1">Hello</button>

    <br><br><br><br>
    Solution - need to add min-width or width in button
    <button class="btn2">Hello</button>

于 2016-11-07T18:11:09.223 回答