What is the best way to ensure that the search box automatically adjusts its position and size regardless of the screen resolution?

I'm currently working on a responsive website project and facing an issue with the absolute positioning of the search bar on the main page, which is crucial for me.

Below is the code snippet:

<div class="span4">

<form class="well form-search" 

style="position:fixed; display:block; 

left: 50%; top: 35.5%; 

margin-top: -12.5px;  

margin-left: -150px;" 

action="{$GLOBALS.site_url}/search-results/">

<input type="text" class="input-medium search-query" value="I am Searching For" 

style="width: 300px; height: 25px; ">

<button class="btn btn-large btn-primary" type="submit" > GO </button>

</form>

</div>

</div>

I've searched extensively and tried different solutions to make it responsive by changing from pixel-based to percentage-based positions, but the problem persists.

While it looks okay on desktop screens, the issue arises when viewed on mobile devices or iPads where the search box placement remains unchanged. I aim to have the search box positioned consistently across various screen sizes.


After tweaking the code, things improved slightly, but now the 'Go' button breaks to a new line instead of staying in the same line. Here's the updated code:

<form class="well form-search" 
style="position:absolute; display:block; 

left: 47.7%; top: 29.5%; 
margin-top: -12.5px;  
margin-left: -22.5%;


width: -webkit-calc(47.7% - 10px);
width: -moz-calc(47.7% - 10px);
width: calc(47.7% - 10px);"


action="{$GLOBALS.site_url}/search-results-jobs/">
<input type="text" class="input-medium search-query"              
value=" I am Looking For" 

style="width: 100%; height: 25px;

width: -webkit-calc(100% - 10px);
width: -moz-calc(100% - 10px);
width: calc(100% - 10px);">

<button class="btn btn-large btn-primary" type="submit" > GO </button></center>
</form>                                                                               

Answer №1

Take a look at this informative blog post discussing the benefits of fixed positioning on mobile devices: .

Answer №2

Check out this link: http://jsfiddle.net/9hR5p/1/

From what I understand, in order to make an input element positioned absolutely fill the full width of its container, you can set both the left and right CSS attributes to 0.

<div class="wrapper">
    <input id="userInput" type="text" name="userInput" placeholder="Type something here">

    <!-- additional content -->

</div>

CSS:

.wrapper {
    width: 100%;
    height: auto;
    position: relative;
}

.wrapper #userInput {
    position: absolute;
    top: 0px;
    left: 0px;
    right: 0px;
}

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

Update the table following the Ajax response in Django

I have set up a filter form which is being sent through an ajax post request: $('#id_server').change(function(e) { $.post($("form").attr("action"), { action: 'filter', filter: $("#id_server").attr("name" ...

What is the method for accessing specific elements by their ID within a chosen HTML document?

First, I am grabbing an element by its id: var toolbarAreaElement = document.getElementById('toolbarArea'); Now, I want to get another element by Id from the previously selected element (toolbarAreaElement) : var subToolbarElement = tool ...

Choosing an option beforehand using angular-ui-select2 version 0.0.5

I'm struggling with setting a default option in a select2 dropdown using Angular and an ng-model. Here's my implementation: Angular controller code snippet $scope.filter = { searchValue: '', departmentId: 'Department2' } ...

Utilizing IndexedDB for data storage

Hey there! I am currently working on storing three fields in an IndexedDB. When I view them in the browser, I see the names of each index - content, content2, and content3. However, only data is being saved into content3. Can you help me figure out why? B ...

Transmitting JSON data object

Sending a JSON Object to JSP Page After following the provided link, I discovered that one of the answers suggests creating a JSON object using the following constructor: JSONObject jsonObj=new JSONObject(String_to_Be_Parsed); Upon downloading the JSON ...

Utilizing Bootstrap Modal to trigger an Action Result function when a button is clicked

I could use some assistance. In my current setup, I have a file picker that loads a file into a specific table in my database. When the user clicks a button, a bootstrap modal pops up to ask if they are uploading more files. This is how it looks in my vi ...

Is the size of the JSON file inhibiting successful parsing?

After retrieving a large list of schools with their respective columns from the database, totaling over 1000 rows, I converted it to JSON and passed it to my view. I then attempted to parse it using $.parseJSON('@Html.Raw(Model.subChoiceJsonString)& ...

Switching icon images using JQuery based on state changes

I'm attempting to switch the background image of my webpage's "body" element when the user toggles between playing and pausing music icons. This is what the CSS for the "body" element looks like: body { background: url('https://s3-us-wes ...

Is there a way to determine the quantity of lines within a div using a Vue3 watcher?

Is it feasible to determine the number of text lines in a div without line breaks? I am looking to dynamically display or hide my CTA link based on whether the text is less than or equal to the -webkit-line-clamp value: SCRIPT: const isExpanded = ref(true ...

A problem arises in Next.js when CSS is not rendering properly during Server Side Rendering

After creating my next.js application using the command npx create-next-app, I realized that the styles from the imported .css files are rendering correctly on Client Side Render but not on Server Side Render. The Next.js documentation states that importe ...

What is the best way to pass a VueJS object to be stored in a Laravel controller?

I am facing an issue with my methods where the data is not getting stored in the database. I am unsure why the information is not being sent to the controller. Even though I input the correct data, it fails to load into the database. However, it does pass ...

Revising the $.parseJSON Function in jQuery 1.9.1 to Match jQuery 1.8.3's Implementation

With the latest version of jQuery, 1.9.0, there have been changes in the implementation of $.parseJSON which is causing some issues for us. We relied on how earlier versions of jQuery handled null and empty strings, where it would return a null value inste ...

Eliminating the 'white-space' surrounding concealed images

I am currently working on a project where I have a list of images that need to be hidden or shown based on the click event of specific <li> elements. While I have managed to achieve this functionality successfully, I am facing an issue with white spa ...

Passing data between Angular 2 components

Below is the component I am working with: @Component({ selector: 'myselector', providers: [ ], directives: [ ChildComponent], pipes: [ ], template: '<myselector>This is {{testEmitter}}</myselector>' }) export cla ...

"Troubleshooting the issue of Delete Requests failing to persist in Node.js

Whenever I send a delete request to my node.js server, it can only delete one item from my JSON file until the server restarts. If I attempt to make a second delete request, it successfully deletes the item but also reverts the deletion of the last item. ...

Are you a fan of Ajax calls using JSON or HTML?

Which method is most recommended for implementing AJAX? If you were developing a search page using PHP and Jquery for the AJAX calls, how would you manage the response? a) Would you prefer to have the response include all relevant HTML and styling? or ...

Experiencing difficulties with parsing JSON data and storing values in a database

I received a JSON response from the server and need help saving the values in a MySQL database using PHP. Can someone please assist me with this? {"fields":[{"label":"Do you have a website?","field_type":"website","required":false,"field_options":{}," ...

Create a JavaScript array containing all the elements from a MySQL table

I am attempting to store my mysql table data in a JavaScript array. My goal is to push each element of the table into the array so that it looks like this: array[0] = [question: information01, answer: information02...] array[1] = [question: information11, ...

The data displayed in the <span> element isn't reflecting the response from the loaded page, despite being visible in Firebug

I have encountered a problem while trying to load a signup.php page into a div on my main page. All the elements (forms, JavaScript, etc.) function correctly in the loaded page, except for one issue - I cannot get the response from the PHP script to displa ...

Searching for an identification using jQuery within a th:each loop

Hey everyone, I'm facing a challenge with my HTML code that uses th:each (spring) to create a list of divs. I need to be able to select a specific button within these divs that opens a bootstrap modal. The modal should display the values of the select ...