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

  • Home
  • SEARCH
  • 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 9243467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:49:04+00:00 2026-06-18T08:49:04+00:00

please take a look at JSFiddle example . I want to make menu with

  • 0

please take a look at JSFiddle example.

I want to make menu with closing ‘x’ on it’s right side. Menu pops-up after click on green div.

HTML

<div class="field">
<nav id="menu">
    <ul>
        <li>Menu item 1</li>
        <li>Menu item 2</li>
        <li>Item 3</li>
    </ul>
    <div class="close">X</div>
</nav>

CSS

.field {
    background: green;
    width: 350px;
    height: 200px;
    margin: 10px auto;
    position: relative;
    cursor: pointer;
}
#menu {
    position: absolute;
    display: none;
}
#menu ul {
    width: 80%;
    border: 1px solid #999;
    float: left;
}
#menu li {
    background: #fff;
    padding: 5% 15%;
    border-width: 0 0 1px 0;
    border-style: solid;
    border-color: #999;
    white-space: nowrap;
}
#menu .close {
    background: #ccc;
    width: 20%;
    padding: 5%;
    float: right;
}

JS

(JS is messy, I wrote it on quickly)

$('.field').on('click', function (e) {

 var $pointer = $('#pointer'),
        $menu = $('#menu'),
        parentOffset = $(this).offset(),
        relX = e.pageX - parentOffset.left,
        relY = e.pageY - parentOffset.top,
        circleX = relX - ($pointer.outerWidth() / 2) + 1,
        circleY = relY - ($pointer.outerHeight() / 2) + 1;

    $pointer.css('left', circleX);
    $pointer.css('top', circleY);
    $pointer.show();

    $menu.css('left', circleX + $pointer.outerWidth());
    $menu.css('top', circleY);
    $menu.show();

    $menu.one('click', '.close', function (e) {
        $menu.hide();
        $pointer.hide();
        e.stopPropagation();
    });
});

There are 2 issues:

  • li items doesn’t overflow properly text inside them;

  • [x] element is under menu and not on its right side;

I tried different combinations suggested in other, similar questions but nothing works or I’m to tired and I missed something.

Important thing is that there should not be any hard coded values. Properly values are only %. That’s because it should look good on different borwser sizes.

Any ideas how to fix those issues?

  • 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-18T08:49:05+00:00Added an answer on June 18, 2026 at 8:49 am

    You should take a look at the CSS Box model. Padding, border and margin are always added to the width/height of the element and are not included in the width you define. Your floating X is jumping down, because there are no more 20% space left on the right side of the ul.

    Better place the X outside of your div. You can also leave out all the floats. Set position: absolute on div.close and move it outside the boundary of the container using left: 100%.

    #menu {
        position: absolute;
        display: none;
    }
    #menu ul {
        border: 1px solid #999;
    }
    #menu li {
        background: #fff;
        padding: 5% 15%;
        border-width: 0 0 1px 0;
        border-style: solid;
        border-color: #999;
    }
    #menu .close {
        background: #ccc;
        width: 20%;
        padding: 5%;
        position: absolute;
        top: 0;
        left: 100%;
    }
    

    By the way, white-space: nowrap leads to your menu elements’ texts being out of the boundary of the li, which is not very flexible.

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

Sidebar

Related Questions

Please take a look at this example. http://jsfiddle.net/LdeWK/2/ I want to know how to
Please take a look at the following example: http://jsfiddle.net/MVfVD/ I want the overlayedFrameFooter div
Please take a look at this: http://jsfiddle.net/tmPfV/ If you click right the box moves
Please take a look: http://jsfiddle.net/JeaffreyGilbert/VkghS/25/ Currently we can drag the bars to the left/right
Please take a look at the fiddle: http://jsfiddle.net/Fyc5d/ Click a gray box, and you'll
Please take a look at the example: http://jsfiddle.net/HHDpK/1/ As you see the difference between
Please take a look at this http://jsfiddle.net/WAre9/4/ The problem is, after changing the text
Please take a look at this example in Chrome browser: http://jsfiddle.net/ymzTB/ <form> <input required
Please take a look at this http://jsfiddle.net/CztkH/6/ I want to run my slide in
http://jsfiddle.net/367ms/1/ Please take a look at my code. So what I want to achieve

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.