Reputation: 47
I have this code for a cute little button
<html>
<head>
<style>
button {
color: white;
font: 18px verdana;
background-color: #6fcafc;
border-style: solid;
border-bottom-color: #60b3e0;
border-width: 0px;
border-bottom-width: 7px;
border-radius: 12px;
padding: 5px;
}
button:active {
border-bottom-width: 0px;
position: relative;
top: 7px;
}
button:focus {
outline: none;
}
</style>
</head>
<body>
<button>Click Me!</button>
<br>
Text that might be here.
</body>
</html>
It moves up and down when I push it. But, because of how it works with moving the button down a bit and removing the border, when I click it, the text below moves up. Could someone please explain to me how to fix this?
Thank you in advance!
Upvotes: 0
Views: 27
Reputation: 432
You can add the same amount of border-bottom-width when the button is active
button {
color: white;
font: 18px verdana;
background-color: #6fcafc;
border-style: solid;
border-bottom-color: #60b3e0;
border-width: 0px;
border-bottom-width: 7px;
border-radius: 12px;
padding: 5px;
}
button:active {
border-bottom-width: 7px;
position: relative;
top: 7px;
}
button:focus {
outline: none;
}
<body>
<button>Click Me!</button>
<br>
Text that might be here.
</body>
Upvotes: 0
Reputation: 22919
You could add a margin-bottom
to the button, to offset the top
value.
button {
color: white;
font: 18px verdana;
background-color: #6fcafc;
border-style: solid;
border-bottom-color: #60b3e0;
border-width: 0px;
border-bottom-width: 7px;
border-radius: 12px;
padding: 5px;
position: relative;
}
button:active {
border-bottom-width: 0px;
top: 7px;
/* added */
margin-bottom: 7px;
}
button:focus {
outline: none;
}
<button>Click Me!</button>
<br> Text that might be here.
Upvotes: 2