我的想法是在用户将其悬停时为提交按钮添加彩色边框。
body div:first-child {
padding: 10px 20px;
background-color: #dedede;
margin-top: 50px;
margin-left: 300px;
width: 120px;
height: 80px;
border-radius: 8px;
}
button {
border-radius: 4px;
padding: 5px 10px;
}
button:hover {
border: 6px solid crimson;
font-weight: 800;
background-color: white;
color: crimson;
}

<div class="container">
<button>SUBMIT</button>
<div>Please notice that ...</div>
</div>
&#13;
但紧随其后的文字会向下移动。
我怎样才能摆脱这些&#34;跳跃&#34;文本同时有边框?
答案 0 :(得分:4)
默认情况下,您需要在button
上定义透明边框,并在悬停时更改border-color
。进一步避免在悬停时更改font-weight
属性,同时它还会扩展按钮的宽度和高度,它会在悬停时跳转。
body div:first-child {
padding: 10px 20px;
background-color: #dedede;
margin-top: 50px;
margin-left: 300px;
width: 120px;
height: 80px;
border-radius: 8px;
}
button {
border: 6px solid transparent;
font-weight: 800;
border-radius: 4px;
padding: 5px 10px;
}
button:hover {
border-color: crimson;
background-color: white;
color: crimson;
}
<div class="container">
<button>SUBMIT</button>
<div>Please notice that ...</div>
</div>
答案 1 :(得分:2)
将“margin”属性添加到“按钮”CSS中,如下所示:
long sum = std::accumulate(begin, end, long{0});
答案 2 :(得分:1)
以下是一些可能性:
答案 3 :(得分:1)
只是为了提供替代方案,您可以使用outline
在悬停时设置“边框”。
body div:first-child {
padding: 10px 20px;
background-color: #dedede;
margin-top: 50px;
margin-left: 300px;
width: 120px;
height: 80px;
border-radius: 8px;
}
button {
border: 0;
border-radius: 4px;
padding: 5px 10px;
margin: 5px 0;
}
button:hover {
outline: 6px solid crimson;
font-weight: 800;
background-color: white;
color: crimson;
}
<div class="container">
<button>SUBMIT</button>
<div>Please notice that ...</div>
</div>
另一种选择:
body div:first-child {
padding: 10px 20px;
background-color: #dedede;
margin-top: 50px;
margin-left: 300px;
width: 120px;
height: 80px;
border-radius: 8px;
}
button {
border-radius: 4px;
padding: 5px 10px;
margin: 6px 0;
border-width: 2px;
border-style: outset;
border-color: buttonface;
}
button:hover {
border-width: 6px;
border-style: solid;
border-color: crimson;
font-weight: 800;
margin: 2px 0;
background-color: white;
color: crimson;
}
<div class="container">
<button>SUBMIT</button>
<div>Please notice that ...</div>
</div>
答案 4 :(得分:0)
立即检查
body div:first-child {
padding: 10px 20px;
background-color: #dedede;
margin-top: 50px;
margin-left: 300px;
width: 120px;
height: 80px;
border-radius: 8px;
}
button {
border-radius: 4px;
padding: 5px 10px;
border: 6px solid transparent;
}
button:hover {
border: 6px solid crimson;
font-weight: 800;
background-color: white;
color: crimson;
}
&#13;
<div class="container">
<button>SUBMIT</button>
<div>Please notice that ...</div>
</div>
&#13;
答案 5 :(得分:0)
尝试将height
添加到按钮
body div:first-child {
padding: 10px 20px;
background-color: #dedede;
margin-top: 50px;
margin-left: 300px;
width: 120px;
height: 80px;
border-radius: 8px;
}
button {
border-radius: 4px;
padding: 5px 10px;
height:40px
}
button:hover {
border: 6px solid crimson;
font-weight: 800;
background-color: white;
color: crimson;
}
&#13;
<div class="container">
<button>SUBMIT</button>
<div>Please notice that ...</div>
</div>
&#13;
答案 6 :(得分:0)
提到按钮的宽度和高度,并删除字体粗细以避免在悬停元素时移动元素。检查以下代码。
body div:first-child {
padding: 10px 20px;
background-color: #dedede;
margin-top: 50px;
margin-left: 300px;
width: 120px;
height: 80px;
border-radius: 8px;
}
button {
border-radius: 4px;
padding: 5px 10px;
height:50px;
width:100px;
}
button:hover {
/*font-weight: 800;
background-color: white;*/
border: 6px solid crimson;
color: crimson;
}
&#13;
<div class="container">
<button>SUBMIT</button>
<div>Please notice that ...</div>
</div>
&#13;
body div:first-child {
padding: 10px 20px;
background-color: #dedede;
margin-top: 50px;
margin-left: 300px;
width: 120px;
height: 80px;
border-radius: 8px;
}
button {
border-radius: 4px;
padding: 5px 10px;
height:50px;
width:100px;
}
button:hover {
border: 6px solid crimson;
background-color: white;
color: crimson;
}
&#13;
<div class="container">
<button>SUBMIT</button>
<div>Please notice that ...</div>
</div>
&#13;
答案 7 :(得分:0)
将与边框大小相同的填充添加到按钮,并在悬停时将其删除。