Move the input field upwards

I have a button that I want to trigger a new input field to slide up when hovered, giving the effect of it coming from behind the button.

Initially, I attempted to achieve this using only CSS by manipulating the height of the surrounding form with overflow: hidden. However, this caused the button to fade out rather than the desired input field. Is there any way to change this behavior, perhaps through a specific browser tweak?

Now, I am exploring jQuery as an alternative solution, although I am not experienced in using it. I am hopeful that someone can provide assistance to make it function correctly.

The key adjustment needed is changing the value of margin from 0 auto -3px to 0 auto -31px.

For reference, here is my example.

Answer №1

If you want to achieve this effect without relying on JavaScript, simply create a wrapping div element.

For example, I created a div with the class "some" (admittedly not the most imaginative choice). When you hover over this div, an input field within it is revealed.

Here's the CSS code:

.some {
    display: inline-block;
}

.some:hover .l-input {
    margin: 0 auto -3px; 
}

.l-button {
    text-transform: uppercase;
    margin: 0 auto;
    display: block;
    width: 7em;
    position: relative;
    cursor: pointer;
}

.l-input {
    margin: 0 auto -31px;
    text-align: center;
    text-transform: uppercase;
    width: 5.9em;
    position: relative;
    height: 1.25em;
    display: block;
}

You can view a working example on JSFiddle at http://jsfiddle.net/c3Veu/.

Update:

Take a look at another demo here: http://jsfiddle.net/sbNym/.

This time, I used absolute positioning so that the input field appears to emerge from behind the rest of the content. Enjoy! (:

Answer №2

Consider using this HTML code:

<div id="content">
    <input type="text" name="application" class="custom-input">
    <button type="button" value="Submit" class="custom-button">code</button>
</div>

Next, add this Script:

$(document).ready(function () {
    $('.custom-button').mouseover(function () {
        $('.custom-input').animate({ bottom: '40px' });
    });
    $('.custom-input').mouseleave(function () {
        $('.custom-input').animate({ bottom: '6px' });
    });
});

Finally, incorporate this CSS:

body {
    padding: 5em;
}

#content {
    position: relative;
    width: 90px;
}

input {
    background: transparent;
    border: 1px solid rgba(155,86,77,0.2);
    /* Additional styles here */
}

.custom-input:active,
.custom-input:focus {
    /* Additional styles here */
}

button {
    /* Button styles here */
}

.custom-button {
    /* Custom button styles here */
}

.custom-input {
    margin: 0 auto -3px;
    text-align: center;
    /* Additional input styles */
}

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

Using jQuery to slide in dynamically generated content

I am in the process of developing a straightforward content slider that has the capability to manage dynamically added content. Unfortunately, none of the supposedly "lightweight" plugins I came across offered this functionality or, if they did, it was not ...

Dynamic file name and title for jQuery Datatables Export Buttons

I am utilizing jQuery datatable along with Export buttons. When adjusting the filename and title, I encounter an issue. The problem lies in my desire for the title to be dynamic, depending on the applied filters and custom ones. Additionally, configurin ...

Retrieve data from a text file using ajax and then return the string to an HTML document

Just starting out with ajax, I have a text file containing number values For example, in ids.txt, 12345 maps to 54321 12345,54321 23456,65432 34567,76543 45678,87654 56789,98765 Here is the Html code snippet I am using <html><body> < ...

Unusual CSS media queries behavior

During my project work, I faced a puzzling issue which can be illustrated with the following example: Here is the sample CSS code: *, *::after, *::before { box-sizing: border-box; margin: 0; border: 0; } @media only screen and (max-width ...

The navigation bar designed with flex boxes is experiencing an issue where the "Login" button positioned on the right is being partially hidden

My website's navbar has a display: flex property to provide padding around the links, but it is causing some issues with overflow. For more details, you can check the JSfiddle link here: https://jsfiddle.net/Bradley_/3bhroby2/3/ I have noticed that m ...

HTML / CSS / JavaScript Integrated Development Environment with Real-time Preview Window

As I've been exploring different options, I've noticed a small but impactful nuance. When working with jQuery or other UI tools, I really enjoy being able to see my changes instantly. While Adobe Dreamweaver's live view port offers this func ...

The information being transferred from a jQuery Ajax request to an MVC ApiController Action is disappearing

Let me first mention that although there are similar questions to this one already posted here, I've tried all the solutions and have not had any success. I have an MVC ApiController Action with the following signature: public void Post([FromBody] E ...

Using the use tag for SVG fills is a great way to

Currently, I am attempting to modify the color of an SVG that is displayed on various pages using the code <svg id="logo-svg"><use xlink:href="#kmc-logo"></use></svg>. You can find the methods I have been experimenting with here: h ...

Enhancing Security and Improving Performance with Subresource Integrity and Cache Busting Methods in

I am in the process of integrating Subresource Integrity and cache busting for my application's static assets like stylesheets and JavaScript files. Currently, I am using PHP with Twig templates. While I am aware of tools available for generating has ...

What is the method for incorporating an upward arrow into a select element, while also including a downward arrow, in order to navigate through options exclusively with

I have a select element that I have styled with up and down arrows. However, I am seeking assistance to navigate the options dropdown solely using these arrows and hide the dropdown list. Here is the HTML: <div class="select_wrap"> <d ...

When using NextJs, running the commands 'npm build' and 'npm start' can sometimes cause style inconsistencies

Currently working on a project with NextJs (sorry, no screenshots allowed). Running 'npm run dev' for development works perfectly fine, but when I switch to 'npm run build' and then 'npm start', the website displays overlappin ...

Using Jquery to dynamically load an aspx page into a specific div element

Yesterday, I posted a question about loading an aspx page in a div tag. I have been using the code below to try and accomplish this, but so far I have been unsuccessful. Can anyone provide assistance on how to successfully load the aspx page into the div ...

Having trouble with elFinder? Encountering an error stating "Undefined is not a function" when attempting to

I am currently in the process of integrating the elFinder file manager into my project. Here is a summary of what I have accomplished so far. I have included the following files: $arr_css = array( "main.css", "jquery-ui.cs ...

Trying to display and conceal images based on the screen size of the device

Just starting out with responsive web design, I'm working on switching between a large image and a small one based on screen width. It's all good when I resize my desktop browser, but when I check it on my mobile phone, the large image is still ...

Is there a way to substitute a custom <form> element for the default <form> in an already existing plugin?

I am currently in the process of customizing a theme and a plugin within WordPress. In the plugin, there is a button that allows users to click on it to bring up a form where they can ask questions. While I want users to post their questions through this p ...

The dimensions of Bootstrap 4.0 card images vary

I am facing a challenge in achieving uniform image sizes for my bootstrap 4 cards. The images themselves vary in size. <div class="container"> <div class="row"> </div> <!-- card 2--> <div class="col-md-6 col-lg ...

Having trouble with crooked Mailchimp text boxes?

After customizing the Mailchimp form on , I added some CSS styles: .mc-field-group{ background-color: #FAFAFA; padding: 10px; } #mce-email { float: left; margin:10px; } #mce-FNAME{ margin:10px; } Although I'm satisfied with ho ...

Discovering a collection of class elements with particular text in Selenium IDE

My objective is to verify that the correct title, summary, and link are displayed in search results. In the scenario below, I aim to ensure that one of the listings includes the title "Title for Beta," a summary with the content "Summary for Beta," and a ...

Transform the color of Max Mega Menu items on hover with another item in WordPress

Seeking help to change the color of my megamenu item when hovering over other items in the menu. Take a look at this image for reference: I've tried using these CSS styles but it didn't work as expected. #mega-menu-wrap-primary-menu #mega-menu-p ...

swapping out an input parameter

Looking for a more efficient way to replace a string in a textarea without causing issues with the script due to "&" characters? function doRequest(){ var str = $('textarea#tr').val(); $.ajax({ type: "POST", url: "index.php?sd=t", d ...