The search bar is visible on desktop screens and can be expanded on mobile devices

Check out my code snippet below.

<style>
#searchformfix {
    width: 50%;
    border-right: 1px solid #E5E5E5;
    border-left: 1px solid #E5E5E5;
    position: relative;
    background: #fff;
    height: 40px;
    display: inline-block;
    border: 1px solid #219AEB;
    border-radius: 5px;
    margin-top: 5px;
}
#searchform {
    margin: 0px 0 0;
    padding: 0;
}
#searchform input[type="text"] {
    background: #fff;
    border: none;
    float: left;
    height: 100%;
    transition: all 600ms cubic-bezier(0.215,0.61,0.355,1) 0s;
    -moz-transition: all 300ms cubic-bezier(0.215,0.61,0.355,1) 0s;
    -webkit-transition: all 600ms cubic-bezier(0.215,0.61,0.355,1) 0s;
    -o-transition: all 600ms cubic-bezier(0.215,0.61,0.355,1) 0s;
    color: #929292;
    margin-left: 10px;
    margin-top: 10px;
    width: 80%;
}
button.fa.fa-search {
    background: #FFF;
    margin-top: 5px;
    font-size: 24px;
    float: right;
    cursor: pointer;
}
</style>
<div id='searchformfix'>
<form action='/search' id='searchform'>
<input name='q' onblur='if (this.value == &quot;&quot;) {this.value = &quot;Search Videos...&quot;;}' onfocus='if (this.value == &quot;Search Videos...&quot;) {this.value = &quot;&quot;;}' type='text' value='Search Videos...'/></form>
<button class='fa fa-search' type='submit' value='Go'></button>
</div>

View the JsFiddle demo here: http://jsfiddle.net/jaribhai/wncwqerj/4/

I have implemented a functional search bar that I want to make expandable in mobile devices similar to this example:

It seems like achieving this may require the use of jQuery. Can anyone provide guidance on how to make this functionality work? Thank you.

Answer №1

To enhance user experience, consider implementing a stylized checkbox to toggle the visibility of the search input field.

Create a visually appealing checkbox with a corresponding label to represent the search icon. Utilize media queries to dynamically display or hide the search input based on the state of the :checked pseudo-class associated with the checkbox.

Check out the live demonstration on: https://jsfiddle.net/abhitalks/ott3Lt78/

Snippet Preview:

* { box-sizing: border-box; padding: 0; margin: 0; }
.srch { margin: 8px; }
.srch > label {
  display: inline-block; text-align: center;
  width: 32px; height: 32px; line-height: 32px;
  background-color: #33d; color: #eee;
  cursor: pointer; vertical-align: middle;
}
.srch > label+input { display: none; }
.srch > input[type=text] {
  display: inline-block; height: 32px; width: 240px; padding: 4px;
  border: 1px solid #33d; transition: width 0.5s;
}

@media screen and (max-width: 700px) {
  .srch > input[type=text] { 
    width: 0; border-width: 0px; padding: 0px;
  }
  .srch > input[type=checkbox]:checked + input { 
    width: 240px; border-width: 1px; padding: 4px;
  }
}
<div class="srch">
  <label for='chk'>&#128270;</label>
  <input id='chk' type='checkbox' />
  <input type="text" placeholder="search videos" />
</div>

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

Refreshing a jsp page without the need to reload the content

On my jsp page, I am displaying the contents of a constantly changing table. This means that users have to refresh the page every time they want to see updated information. Is there a way for me to update the content dynamically without requiring users t ...

I am interested in incorporating a vertical scrollbar into a gridview in ASP.NET

I've successfully bound data to a grid view in my ASP.NET application. I've implemented pagination, but instead of that, I'd like to incorporate a scroll bar to prevent lengthy paging. Below is the code for my grid view: <div class="box ...

Issue with Jquery slideToggle not remaining in the down position

I'm currently working on implementing a sub-navigation menu that slides down when links in a separate div are clicked. Although I've managed to hide the sub-nav properly, I'm facing an issue where it briefly appears and then hides again afte ...

Can $.ajax be used as a replacement for $(document).ready(function()?

After conducting an extensive search, I am still unable to find a clear answer to my assumption. The code I used is as follows: <?php session_start(); if (isset($_SESSION['valid_user']) && $_SESSION['from']==1) { ?> ...

Using CSS files that are not properly imported into React components

Currently, I am utilizing multiple CSS files for a specific purpose. The issue I am facing is that when I apply styles to one component in a CSS file, it inadvertently affects other components as well, not just the intended one. I believe the root of this ...

Is there a way to run only one instance of puppeteer.launch() and simply forward pages to it in Node.js?

I have a concern regarding the code snippet below. It appears to be launching the browser on every request, potentially causing server issues on Heroku. I would like to modify it so that puppeteer is launched as a Singleton instance, where it only needs ...

An error occurred while the server was processing the request during an Ajax POST operation

My jQuery Mobile app communicates with a WCF REST service, and most of the calls to the service are GETs. However, one particular function uses a POST request with JSON data. While the POST request works perfectly on our development servers, it fails to w ...

Utilize this JavaScript tool to effortlessly transform an XML string into JSON format

Looking for the optimal javascript function, plugin, or library to effectively transform an XML string into JSON format. One tool I came across is , but unfortunately, it struggles with strings that begin with 0. For example, 005321 may end up converted t ...

The issue of JQuery recursion not properly focusing on a textbox

Can anyone help with a jquery focus issue I'm experiencing? My goal is to address the placeholder problem in IE by focusing on an element and then blurring it to display the placeholder. This functionality is being used in a modal form. Initially, e ...

Generate pre-set components using fundamental building blocks

Can I predefine some props for components? In my Vuetify example, let's say I want to customize the v-btn component with specific props. This custom implementation would act as a child component while still providing all the functionalities of the par ...

Incorporating a transparent icon onto an HTML background

I'm struggling to place a transparent white envelope icon on a green background. I don't understand why it's not working, especially when the telephone icon worked fine. Side Question.: Any recommendations for how to add something above the ...

Error: Attempting to access the 'toString' property of an undefined object is not permitted (apex-charts)

While working on a personal project, I considered using apexcharts. However, an error shown in the image kept popping up. It seemed to disappear when I set the width and height properties in the Chart component or when the site was in production. Currently ...

Leveraging the X-Send module for efficiently delivering css, javascript, and image files

I am in the process of setting up a file server that currently serves downloadable files such as .doc and .zip perfectly using X-Send. Is it also possible to use X-Send for serving text-based (css/javascript) or image files? I believe this method is quite ...

Utilizing ReactJS to make an Ajax request

I am trying to transfer data to individuals and then display it using the array map function. export default class App extends Component { constructor(props) { super(props); this.state = { persons: [], }; } componentDidMount() { $ ...

parsing an array using jQuery's getJSON

Finally got the simplified array to work, check it out below If you're still struggling with parsing a complicated array, you can refer to this link. TLDR: I need to extract and insert each heading from an array into a div using Jquery - getJSON, wi ...

Significant contrast in how text is displayed between Chrome and Firefox

Experiencing significant discrepancies in text rendering between Chrome and Firefox. Chrome appears to apply anti-aliasing rules that reduce the text size considerably. Attempts have been made to adjust -webkit-font-smoothing, letter-spacing and word-spac ...

The range slider initiates with the first alphabet

I have created a range slider with values from 0 to 4, displaying as 0, 1, 2, 3, 4. Currently, the minimum value is set as 0 and the maximum value is set as 4. Now, I am looking to replace 0 with 'F'. For example: F, 1, 2, 3, 4. Is it possible t ...

The issue of nested tabs in Bootstrap 3 causing problems with sliders within the main tab has

Hello, I am utilizing Bootstrap 3 tabs. Within the nav-tabs, there are three tab-panes: the first tab contains text only, the second tab includes a slider, and the third tab has nested tabs. However, I encountered an issue where the slider in the nested t ...

Error: The login is invalid due to authentication failure with code 535 5.0.0

I'm currently working on setting up Outlook calendar events by integrating a mailing service with my project. I'm using the Express framework and Mongoose queries for this purpose. Below is the code snippet I have implemented: var _ = require(& ...

Do you mean using a JSON object as a value?

When creating a JSON object where the value itself is an object, what is the correct way to write it? var data ='{"phone":{"gtd": "080"}}'; OR var data ='{"phone":"{gtd: 080}"}'; This question may seem straightforward. I am curious ...