Toggle the slide when you hit submit

I'm considering the functionality of my code.

I am interested in creating a slide toggle effect on a div or span when hovering over an input submit button. Here is an example:

https://i.sstatic.net/pBSK8.png

What is the best approach to achieve this? Should I insert a span before the submit button?

Alternatively,

Could I add content using .submit:before instead?

Answer №1

Is this what you're looking for? No need for JavaScript.

button {text-decoration: none; background-color: #99f; color: #fff; font-family: Segoe UI; display: inline-block; border: 0; padding: 0; cursor: pointer;}
button span {display: inline-block; -webkit-transition: all 0.5s ease; -o-transition: all 0.5s ease; transition: all 0.5s ease; vertical-align: top; padding: 10px 2px;}
button span:first-child {width: 0; padding: 10px 0; overflow: hidden; background-color: #999;}
button:hover span:first-child {width: 25px; padding: 10px 0 10px 10px;}
<button type="submit">
  <span>Go</span><span>Submit</span>
</button>

Answer №2

To achieve this effect, implement CSS transitions in your code.

Here is the HTML structure:

<div class="box">
  <span>Hover!</span>
  Transition
</div>

And here is the corresponding CSS style:

.box:hover {
  span {
    width: 50px;
  }
}

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

How can I adjust padding values specifically for mobile devices within the Bulma CSS framework?

After constructing a website with the Bulma CSS framework, I encountered an issue with padding on mobile devices. To optimize the user experience, I need to reduce the padding on smaller screens to 5% or less instead of the initial 10%. However, I am unsur ...

Writing a function to determine if an HTML element is present

Is there a way to create a function that checks for the existence of an element with a specific id? I have a list of IDs stored in an array: let CartArray = ["cart-0", "cart-1", "cart-2", "cart-3"]; This is the Java ...

The issue of Bootstrap modals failing to show content when a button is clicked within the Django Framework

My Bootstrap modals in the HTML code are causing issues as they do not display any content when the triggering buttons are clicked. Despite having correct IDs and attributes, the modals remain empty when the buttons are clicked. Below is the relevant part ...

Customize the arrow color in a TextField Select component from material-ui

Having some trouble changing the color of my arrow icon within the Material-ui TextField Select. Here's what I've tried: icon: { fill: "white !important", }, Despite applying these props, the color remains unchanged. I've experimen ...

The body's width is more compact compared to one of my containers in HTML/CSS

After completing my code for a beginner's HTML/CSS project, I realized that the main parent container holding two smaller containers needed to be set at specific widths. The two inner containers had to be exactly 650px and 270px wide, while the main p ...

Avoid triggering the sum button on click after every successful AJAX call in jQuery

Hello, I apologize if my title question is not clear as I am a bit confused. Let me explain the scenario: I am creating a looping post timeline similar to Facebook, where each post has comments. The structure is as follows: ++++++++++++++++++++++++++ Po ...

What is the reason that a <button> tag is unable to include a <div> element within it?

While developing our company website, we encountered a challenge with a JavaScript library failing to replace a certain element. In an attempt to troubleshoot, we ran our HTML code through the W3C validator and discovered that nesting a <div> tag wit ...

The feature of Jquery click and cursor: pointer only focuses on a single element at a

Recently, I created a navbar that includes a dropdown feature. I encountered an issue where I wanted the dropdown to show up when clicking on the navbar-profile class (which contains the profile picture, name, and chevron icon) in the top right corner. Ho ...

Transferring PHP array to JavaScript with the help of AJAX

I've been working on integrating Google Maps and Instagram in a project of mine. My main challenge is figuring out how to pass the coordinates of Instagram photos from my PHP file to my JavaScript file using AJAX. I'm quite lost when it comes to ...

CSS login validator immobilized

In my Visual Studio project, I am facing an issue with applying CSS to two requiredfield validators. I have tried using the following code: #vdtrUserLogin { top:65px; left:750; position:absolute} #vdtrPasswordLogin0 { top:65px; left:900; position:absolute ...

What is the best way to ensure the dropdown box in a Bootstrap navbar automatically adjusts its width to fit within the

When I click on the dropdown menu, the box extends beyond the width of the page and a horizontal scroll appears. How can I make the dropdown box automatically adjust its position if it reaches the edge of the page without needing a scroll (as shown in the ...

Modify CSS using JavaScript at a specific screen size

Currently, I am in the process of designing a responsive navigation system which involves implementing a button that dynamically changes the styling of the div #navigation using Javascript. The aim is to toggle between display: none; and display: block; ba ...

Tips for effectively utilizing innerHTML in this particular scenario

For an assignment, we were tasked with creating a Madlib game where users input words into textfields to replace certain words in a hidden paragraph within the HTML using JavaScript and CSS. The paragraph embedded in the HTML page is as follows: <span ...

The elements on the webpage adjust their dimensions accordingly when zooming in or out

I have been facing an issue with the menu width on my webpage. When I zoom in and out, the width of the menu keeps changing. This problem only occurs in browsers other than IE. I have checked for fixed positioning but it appears to be using relative positi ...

What is the best way to adjust the height of a Div to be 100%?

I've been struggling to make the .footer and the div .content have a height of 100%. While I know how to get the footer to stick at the bottom, I can't seem to make the content div reach the bottom of the page. Increasing the min-height on the co ...

What causes the button size to change in Bootstrap when switching to a spinner?

Every time I switch from a spinner back to a button, the button's size changes. I am struggling to identify the cause of this issue. function resizeButton() { var btn = document.getElementById('submitBtn'); btn.innerHTML = ' ...

Unable to assign a className to a personalized React component - troubleshooting needed!

I have a component that relies on another component. I am trying to pass CSS positioning from the outer component to the inner one by using the following code: import OptionsMenu from './OptionsMenu' import { withStyles } from 'material-ui/ ...

Choose and manipulate a set of elements using Jquery

Below is a piece of code I have: <div class="timeline"> <div class="timeslice" data-tid="360"></div> <div class="timeslice" data-tid="360"></div> <div class="timeslice" data-tid="360"></div> <di ...

How can I incorporate a .shtml file into a .php webpage?

Is there a way to include a .shtml file within a .php page? I know it can be done, as I have successfully achieved this in the past (although I cannot remember the exact code). Can someone please assist me with this? ...

Tips on optimizing website performance by implementing lazy loading for images and ensuring they are ready for printing

Many websites feature an abundance of images, prompting the use of lazy loading to enhance load times and reduce data consumption. But what happens when printing functionality is also required for such a website? One approach could involve detecting the p ...