Back
Simple tutorial on how to create a button that increases on hover and changes text, using only HTML and CSS.
<button> <span>i</span> <span class="nfo">NFO</span> </button>
button { border: none; cursor: pointer; width: 30px; height: 30px; border-radius: 15px; background-color: rgb(255, 128, 0); color: #fff; display: flex; justify-content: center; align-items: center; transition: .3s; }To "nfo" class, we'll set width and opacity to zero and transition to 300 milliseconds.
.nfo { width: 0px; transition: .3s; opacity: 0; }On button hover, we'll select the "nfo" class and set width to 20px, opacity back to 1 and, of course, the transition , so that this width change is smooth.
button:hover .nfo { width: 20px; transition: .3s; opacity: 1; }Lastly, the button element on hover, we'll just increase width and set transition.
button:hover { width: 80px; transition: .3s; }And that is it.
<button> <span>i</span> <span class="nfo">NFO</span> </button> <style> button { border: none; cursor: pointer; width: 30px; height: 30px; border-radius: 15px; background-color: rgb(255, 128, 0); color: #fff; display: flex; justify-content: center; align-items: center; transition: .3s; } .nfo { width: 0px; transition: .3s; opacity: 0; } button:hover .nfo { width: 20px; transition: .3s; opacity: 1; } button:hover { width: 80px; transition: .3s; } </style>Thank you for reading this article.