Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:10:34+00:00 2026-06-01T11:10:34+00:00

I have created a search feature for a site and in addition I made

  • 0

I have created a search feature for a site and in addition I made a “suggestions box” that drops down based on what they are typing. (Like Google does!)

So my issue is, the box floats out of position depending on the window size. How do I fix it to the bottom of the search field?

Live example found here: http://swissinstruments.com/searchresults.php (see top search field, type “a” or “c” to get some suggestions coming down.

Now for some code of what I am using:

The Suggestions Box STYLE

.suggestion_list
{
z-index:500;
background: white;
border: 1px solid #80B6E1;
padding: 4px;
float:none;
margin-top:5px;
width:191px;
position:fixed;
}

.suggestion_list ul
{
padding: 0;
margin: 0;
list-style-type: none;
}

.suggestion_list a
{
text-decoration: none;
color: navy;
}

.suggestion_list .selected
{
background: navy;
color: white;
}

.suggestion_list .selected a
{
color: white;
}

#autosuggest
{
display: none;
}

The SEARCH BOX Style
#search-form { float:right; padding:9px 0 0 0;}
#search-form fieldset {
border:none;
border:1px solid #0f58a2;
border-top:none;
background:#126dbe;
padding:0 12px 10px 13px;
 float:right
}
#search-form input.text { width:190px; border:1px solid #d0e0e6; margin-right:3px;     padding:2px 2px 3px 7px;}
#search-form input.submit { background:#007cff; width:59px; text-align:center;     height:23px; line-height:23px; color:#fff; font-size:.77em; text-transform:uppercase;   border:none; cursor:pointer;}

Finally the JavaScript part that is used to position the div. I have set the x to -164 since it seems to work for the resolution used by most users. But as soon as I shrink or stretch it the box is out of position.

/********************************************************
Position the dropdown div below the input text field.
********************************************************/
this.positionDiv = function()
{
    var el = this.elem;
    var x = -164;
    var y = el.offsetHeight;

    //Walk up the DOM and add up all of the offset positions.
    while (el.offsetParent && el.tagName.toUpperCase() != 'BODY')
    {
        x += el.offsetLeft;
        y += el.offsetTop;
        el = el.offsetParent;
    }

    x += el.offsetLeft;
    y += el.offsetTop;

    this.div.style.left = x + 'px';
    this.div.style.top = y + 'px';
};

Is there any way to use percentages rather than px?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:10:36+00:00Added an answer on June 1, 2026 at 11:10 am

    You could do this using nested divs and relative/absolute positioning in CSS, you don’t really need javascript to position the dropdown.

    something like this should be flush, assuming search-form has no padding/margins

    #suggest_container { position:relative; overflow:visible; }
    #autosuggest { position:absolute; top:<height-of-search-form>; left:0px; }
    
    <div id="suggest_container">
        <form id="search-form"></form>
        <div id="autosuggest"></div>
    </div>
    

    you could also always use jquery UI autocomplete widget, I’ve used it quite a bit before and it’s fairly robust

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a keyword search in SQL that takes a list of keywords
Good Morning, I have created an ASP.NET 3.5 webform that allows users to search
I have created a search bar for my website, the user may search a
I have created a Google Search function, however I would like to leave the
I have created an on the fly search field in Java Swing. I have
I just started programming in Basic4android. I have created 2 layouts. splash and search
I have a website, I've created with a 'Custom Search' functionality. I set it
I have an search box with under the search box an webview. when i
I have created a page where I perform a search and the number of
I'm working on a search feature in one of my Core Data based apps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.