Elevate when the mouse hovers over the button

My current task involves increasing the bottom-padding of a span when the mouse hovers over a button. Here is the button code:

<button class="btn btn-success btn-circle" id="myBtn" title="Go to top">
    <span id="move" class="fa fa-chevron-up"></span></button>

To accomplish this, I attempted to create a class with increased bottom-padding (13px) using JavaScript.

Here is the class I created:

.set {
        padding-bottom:13px;
    }

And here is the JavaScript code I used:

window.onload = function() {
        document.getElementById("myBtn").onmouseover = function() {
            document.getElementById("myBtn").classList.add(" set");
        }
    }

Unfortunately, this approach did not yield the desired results. Can anyone provide assistance? The objective is to revert the span's bottom-padding back to its default value of 3px when the mouse is no longer on the button. Thank you!

Answer №1

To achieve this effect, you can utilize CSS in a simple way:

.btn-circle:hover span{
 padding-bottom:13px;
}

Explanation

 :hover // triggers when mouse enters an element

Make sure to use padding-bottom:13px; instead of padding-bottom=13px;

Answer №3

Eliminate the space in your class assignment from " set" to "set". To avoid repeating the getElementById method on the DOM, you can assign it to a variable like elem.

window.onload = function() {
  var elem = document.getElementById("myBtn");
  elem.onmouseover = function() {
    elem.classList.add("set");
  }
}
.set {
  color: red;
}
<button class="btn btn-success btn-circle" id="myBtn" title="Go to top">
<span id="move" class="fa fa-chevron-up">someIcon</span></button>

Answer №4

It's a bit unclear, but I believe you're trying to move the inner span upward without increasing the padding of the button itself. Here's a possible solution:

#myBtn:hover #move {
    position: relative;
    top: -3px; // adjust as needed
}

You could make this movement animate smoothly like this:

#move {
    position: relative;
    top: 0px;
    transition: all ease-in-out 0.3s;
}   

#myBtn:hover #move {
    position: relative;
    top: -3px; // adjust as needed
}

Just a heads up, there are other responses suggesting the use of `padding-bottom`, but keep in mind that it will impact the parent's size. Using `top` in combination with `position: relative` is a more stable approach.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CSS border margin-bottom attribute not functioning correctly

I am trying to create a page border by wrapping it around the content using a <div> element. The parent element is the actual page itself. However, I'm having trouble with the margin-bottom property as it doesn't seem to be working properly ...

CSS grid layout for box alignment

I need the first two boxes to be positioned at the top with maximum width and the following two boxes to be placed at the bottom with the maximum width. Below are the CSS and HTML codes provided: CSS Code: /* Start Services */ .services { padding-top ...

Dynamic Navigation Menu: Subcategories Crossing Over Menubar Items

Task Clarification Lately, I've been working on developing a left-side navigation bar for my webpage. This bar consists of two levels of items. When viewed on a smaller device, only the icons of the first level appear. Hovering over these icons trigg ...

Is there a way to deactivate the minutes input feature in the Angular UI Timepicker?

I am using a plugin that displays the time in hours and minutes. However, I only need to show the hours. Is there a way to hide the minutes block? This is my HTML code: <uib-timepicker ng-model="mytime" ng-change="changed()" hour-step="1" minute-step ...

Utilizing Python to dynamically create unique tags from deeply nested dictionaries through recursion

As part of my project, I am developing a unique dynamic template tool that can seamlessly integrate with any templating framework such as pugs and jinja. The goal is to create a demo that resembles the following structure: view! { div { p { ...

What steps can be taken to ensure that the scale() function is given the highest priority

Trying to develop a program that generates a canvas graph based on some calculated data. To adjust for larger numbers, I attempted to scale the graph using ctx.scale();. However, every time I do this, the canvas goes blank! I even tried scaling the canvas ...

Issue: AngularJS not refreshing view after receiving server response

Currently, as I work on developing a mobile application, I've come across an issue related to relaying messages in the view after executing an ajax call and receiving data from the server. My goal is to display these messages to users only after they ...

What is the best way to duplicate this content from a picture using CSS?

Trying to replicate text in an image using HTML and CSS. Wondering if there's a better way than setting each line with its own font size. Here's the image I'm working on: https://i.sstatic.net/bMPhy.png Current issues with the approach: ...

Java servlet, Selenium, and JavaScript are a powerful combination of tools that can

I am facing a situation where I need Selenium webdriver to be executed on the client side. On a webpage, I have a form with a Submit button inside it. The action attribute of the form calls a servlet named "servletName". Inside the servlet, the followin ...

Having issues with a Retina iPhone interacting with a website built using responsive Twitter Bootstrap

I'm currently utilizing Twitter Bootstrap alongside responsive CSS for a web page that is optimized to run in a UIWebView. My goal is to ensure the consistency of the page's appearance across all iPhones, with an exception for images. These imag ...

Utilizing the HTML5 Download attribute for linking to external files

I am currently developing a web application for my own personal needs. One feature I would like to implement is the ability to set the download attribute on certain links. However, I have run into an issue where the files to be downloaded are hosted on ex ...

Solving Issues with URL Parameters and AJAX

My JSP page has a JavaScript function called loadData() that is triggered when the page loads. This function makes an AJAX request to a servlet in order to retrieve data and return the necessary HTML content to display on the page. I am trying to call thi ...

Establishing a dynamic database feature (such as a real-time leader board) on a website

Recently, I designed a fun JavaScript game for my website and now I am contemplating adding a leaderboard feature. However, I am unsure about which type of database would be the best fit - MongoDB, SQLite, or something else entirely. I have heard that SQ ...

Using ThreeJS to project a mouse click onto the XZ plane

I am currently working on implementing offline routing in a 3D map within a ThreeJS scene. My goal is to allow the user to click on a point and have a cube navigate to that point. While the navigation functionality is working correctly, I am facing an issu ...

What is the best way to ensure a div occupies the full height within a grid layout?

https://i.sstatic.net/awwxE.png Looking at the image provided, I am seeking a way to make the top left image occupy the entire height just like the neighboring div in the first row of the grid. Is there a way to achieve this? The desired outcome should b ...

Retrieve data from an HTML table using PHP

This snippet of code is encapsulated within table tags and retrieves data from a database to populate the table. Within the database, there is an auto-increment column named 'id'. The objective is to obtain the 'id' value associated wit ...

What is the process for implementing Sequelize to manage and modify multiple tables simultaneously?

I am currently working on developing the back-end with DB using Sequelize ORM. My main challenge is creating or updating data in multiple tables simultaneously. Below are some examples of what I am trying to achieve: //Tables const main = sequelize.define ...

Tips for adjusting the color of multi-line text when hovering with the mouse

I'm facing a challenge in changing the color of text when someone hovers over it, but so far I've only been able to make it work if the mouse scrolls over the top border of the text. The text I'm testing is located in the top left corner an ...

Is the order of elements in a CSS file important?

In my situation, I am dealing with a nested list and enclosing div that was created by Drupal's menu system, so I am unable to modify it. My goal is to replicate the menu from a hardcoded website (link removed). How can I include the sub-items (ul l ...

Error Encountered in Jhipster Application During Initial Launch

Struggling with running a newly generated Jshipster 3 application using gulp serve after successful generation. My setup includes Ubuntu 16.04 and npm 3.9, but I keep encountering an error when attempting to execute gulp serve: check out this screenshot ...