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 6957567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:01:12+00:00 2026-05-27T15:01:12+00:00

I am trying to make a ‘dropdown’ menu style of which its a div.

  • 0

I am trying to make a ‘dropdown’ menu style of which its a div. When a button will be pressed the div will appear at a position exactly underneath it.

Here is an example from google’s translator:
enter image description here

This is a div and its positioned exactly underneath the button, using left and right.

How can you do this without specifying exactly the left and right because I can’t know the screen size of the user. Also this has to be cross browser.

This is what I currently have:
http://jsfiddle.net/pCg9N/

  • 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-05-27T15:01:13+00:00Added an answer on May 27, 2026 at 3:01 pm

    You could do something like this:

    $(document).ready( function() {
        // So that we don't have jQuery search every time.
        var $button = $("button");
    
        // Button's left offset, relative to the document.
        var buttonLeft = $button.offset().left;
        // Button's right offset, relative to the document.
        var buttonTop = $button.offset().top;
        // innerHeight() includes CSS padding.
        var buttonHeight = $button.innerHeight();
    
        // Finally, set the div's left and top CSS attributes.
        $("div").css("left", buttonLeft + "px");
        $("div").css("top", buttonTop + buttonHeight + "px");
    });
    
    $('button').on('click', function () {
        // I changed this to toggle() so that it hides again if clicking twice ;-)
        $('div').toggle();
    });
    

    Basically now it’s making use of the button’s positioning information so you never have to set it on the div. This should help, but unfortunately cross-browser support isn’t necessarily this simple.

    I also changed the CSS around a little in your example to better illustrate what we’re doing, see updated version below for the full thing:

    http://jsfiddle.net/pCg9N/15/

    Links to relevant jQuery function documentation:

    • offset()
    • css()
    • innerHeight()
    • toggle()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to make a page which will recursively call a function until a limit
Trying to make a floating css menu. How do I get the floating div
I'm trying make a static text which if too long for the sizer, will
Trying to make a simple toggle menu, and I can't seem to hide/show the
Im trying to make custom icons for my HTC EVO, which is running Cyanogen
I am trying make such application which speak automatically when the image loaded it
Trying to make simple jQuery function to create a scrollToTop button that fades in
Im trying make a menu with the next structure: -category 1 --category 1.1 ---category
Im trying to make a popup div (when a text-box value changes) and it
Im trying to make a quite simple game but its having an error. I

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.