Expand nested Divs in the search field

I am working on creating a search bar that consists of a search input, an Options button, and a 3rd button that expands to the left when hovered, pushing the previous elements over.

Despite my attempts with CSS, I have been unable to smoothly slide the other elements over. I suspect this may need to be implemented with jQuery instead?

When the user hovers over the arrow, the div should open to the left and reveal the word 'search' alongside a 20% gray overlay.

The 'options' button is supposed to slide to the left while the search button expands, but the width of the entire search wrap should remain unchanged and in place.

This is where I currently stand in terms of code:

HTML:

<div class="search-box">
    <input name="" type="text" placeholder="search" class="input"><a href="#" class="option">options</a>
            <div id="search-button">
                <div id="search-button-text">search &nbsp;</div>
                <a href="#"><img src="/static/images/search-btn.jpg" alt=""></a>
            </div>
        </div>

Some unsuccessful JS attempts:

$(".search-button").hover(function() {
    $('search-button-text').style.display = 'block-inline';
});

The CSS:

.search-box {
    width:582px;
    float:right;
    clear:both;
}

.search-box .input {
    float:left;
    /*min-width: 500px;*/
    border:1px solid #231f20;
    height:25px !important;
    font:16px "JosefinSans Regular", Arial, Helvetica, sans-serif;
    margin:0px;
}

.search-box .option {
    display: block-inline;
    float:left;
    height:20px !important;
    width: 50px;
    border:1px solid #231f20;
    padding-top:7px;
    text-align: center;
    border-left:none;
    border-right:none;
    color:#000;
    text-decoration:none;
    font-size:13px;
}

#search-button {
    display:inline-block;
}

#search-button-text {
    display: none;
    visibility: hidden;
}

Answer №1

I have successfully implemented a slide effect using the CSS3 transition property. If you'd like to see the output, please check out this demo link. I made some modifications to the HTML and added the necessary slide CSS for this effect.

Here is the modified HTML:

<div class="clearfix searchbox">
   <input type="text" />
   <a href="#" class="searchbutton">
        <span class="searchtext">Search</span>
        <span class="arrow">&#8594;</span>
   </a>
   <a href="#" class="option">Options</a>
</div>

And here is the added CSS:

* {padding: 0; margin: 0;}
.clearfix:after {clear: both; content: ' '; display: block; font-size: 0; line-height: 0; visibility: hidden; width: 0; height: 0;}
.clearfix {display: inline-block;}
* html .clearfix {height: 1%;}
.clearfix {display: block;}
.searchbox {width: 500px; border: 1px solid #000; font-family: Arial, Helvetica, sans-serif; font-size: 13px;}
.searchbox input {height: 20px; padding: 5px; border: 0px solid #000; width: 360px; outline: 0;}
.searchbox a {line-height: 30px; color: #000; float: right; display: block; text-decoration: none; padding: 0 5px;}
.searchbox a span {float: left; display: block;}
.searchbox a.option {border-right: 1px solid #000; border-left: 1px solid #000;}
.searchtext {width: 41px; width: 0; display: inline-block; overflow: hidden; -webkit-transition: 300ms all; -moz-transition: 300ms all; -o-transition: 300ms all; transition: 300ms all;}
.searchbutton:hover .searchtext {width: 45px;}
.searchbutton:hover {background: #f2f2f2;}

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

The image seems to be misaligned inside the DIV, and interestingly, this issue appears to be

http://jsfiddle.net/Bzpj4/ The situation depicted in the DIV above is quite puzzling. A 120x120 image is contained within a 120x120 DIV, which is then placed inside a larger DIV with a height of 120px. Strangely, the image within the larger DIV seems to b ...

I am struggling to make the while loop in JavaScript stop even when I command it to

var dataStatus = '1'; while (dataStatus != 0) { $.ajax({ url: '/ajax.php?updateData='+dataStatus, dataType: 'json', async: false, success: function(response) { dataStatus = respo ...

How to deactivate or modify the href attribute of an anchor element using jQuery

My HTML code looks something like this: <div id="StoreLocatorPlaceHolder_ctl07_ctl00_ctl00_pager_ctl00_ctl00_numeric" class="sf_pagerNumeric"> <a href="http://www.domain.com/store-list">1</a> <a href="http://www.domain.com/sto ...

What is the best way to center an absolutely positioned div within Internet Explorer 7?

ENSURING PROPER LAYOUT CONTEXT I am working with a simple layout for my webpage. It consists of two divs that are both positioned absolutely, with one centered within the other. <div id="protocol_index_body_wrapper"> <div id="protocol_index_ ...

New toggle button for Twitter Bootstrap 3 navbar featuring unique icon symbol

Looking to enhance my mobile navigation using Twitter Bootstrap 3 by adding an additional navbar. The navbar will feature two toggle buttons on each side - the left button will have the classic "three bar" icon, while the right button will have a differen ...

Instantly refresh dropdown menu after a change event

Whenever a dropdown list is changed, I have it populate with options through a jQuery AJAX call. Here's the code that handles this event: //dropdowns switching $("#eventActivity").bind("change", (function() { ...

Is it possible to use jQuery datepicker to accept partial dates, such as "05/"?

I have a Date of Birth field displayed as a textbox connected to a date picker. The following is the HTML code: <input class="text-box single-line hasDatepicker valid" data-val="true" data-val-date="The field Birth Date must be a date." data-val-requir ...

Refresh the data in a table upon clicking the menu

I am looking to develop an accordion MENU, but unsure if I should use divs or <ul>. When a submenu is clicked, I want to execute a mysql query to update the data in the table next to the menu. I'm not sure of the best approach and whether to uti ...

What is the reason behind the $post not functioning while $ajax works successfully on the asp.net web api controller?

I'm curious about why the $.ajax() request is successful, but the $.post() method only returns an empty array on the controller. Here's the controller code snippet: [Route("api/actuary/{actuaryId:long}/documents/")] [HttpPost] public async Task ...

What is the process for specifying a specific font family in CSS?

Despite setting my text to font-family: Times New Roman, I'm seeing a different font in my Chrome browser. Here is the relevant HTML code: <p style="color:#F17141;font-size: 120px; font-family: &quot;Times New Roman&quot; ; font-weight: b ...

Performing an Ajax request in Django

Currently using Django and have created a delete button function. It's working perfectly for the /employer/job/edit URL, but encountering issues with the vendor/job/edit URL. The template is shared between these two places and my code works for one bu ...

Enabling the `dbc.Select()` function to require a dropdown selection in DASH does not automatically highlight an empty dropdown

While working on my plotly-Dash form, I utilized bootstraps dbc.Select() to generate a dropdown. I hoped to have it outlined in red, similar to my dbc.Input() boxes, when no option is selected. However, the red border is not showing up. I set required = ...

Calculating the time difference in days, hours, minutes, and seconds between two UNIX timestamps

I have a special occasion coming up, and the date and time for this event are stored in a Unix timestamp format. Instead of relying on a plugin like modern.js, I am trying to figure out the time difference between today's date and the event date usin ...

Display sourcemaps on Chrome's network panel

Recently, I began utilizing source maps for my SASS code in order to debug more efficiently in Chrome. My understanding was that Chrome should request both the stylesheet resource and the .map resource, however, only the stylesheet is visible in the netwo ...

Issue with input-group background display in bootstrap 4

My new computer is running on Windows 11 with Chrome version 97. There seems to be a bug in the original bootstrap code, as evidenced by the attachment. The issue can be seen on the Bootstrap website By adding "border-radius:0!important" to ".input-group ...

Inquiries about the jQuery Button Timer

Currently experimenting with jQuery to create a timer. Everything seems to be in place and the Stop Timer button is functioning properly. However, I'm facing issues with the Start Timer and Reset Timer buttons as they are not working as expected. Seek ...

The image shape at the bottom of the screen may disappear on certain resolutions

I've added a unique curvy shape at the bottom of the image on a bootstrap card I designed using bootstrap 5. Everything looks great on resolutions above 1400px, but on smaller screens, the shape disappears, leaving the image rectangular. I've tri ...

Change the visibility of a div element by leveraging the data-target attribute

Hey there, I have a question about how to use the data-target attribute to set the display of a div. Check out my HTML code below: <div class="page page-current" id="home"> PAGE 1 <a href="#" class="next" data-target="#about">Go to about< ...

What could be causing my Link to malfunction in my about.js file?

I've encountered an issue where clicking the link in my app doesn't produce any result, and I'm unsure of the cause. Below is the content of my app.js file: import './App.css'; import {BrowserRouter as Router, Routes, Route} from ...

Creating a dependency between two checkboxes using jQueryFeedback: Looks good!

Looking for help with jQuery code to make two checkboxes dependent. When checkbox1 is checked, checkbox2 should automatically turn on. Here's my current code: //php $cus_centre = $this->createElement('checkbox', 'checkbox1'); ...