Challenges regarding placement and z-index are causing issues

Currently, I am attempting to make the menu overlap the content on my webpage. However, I am facing an issue where it moves the content box instead of overlapping it.

I have already experimented with the position: relative concept, but unfortunately, the problem persists. It seems like the solution is right in front of me, but I could use some guidance in identifying it.

EDIT: Apologies for the oversight, I forgot to mention that the box will also need to be resizable(), hence why I am trying to avoid absolute positioning. EDIT2: Disregard the previous edit, using right:5px resolves the issue.

JSFiddle

HTML

<div class="box">
    <div class="top">
        <div class="icon"></div>
        <div class="menubox">
            <ul class="menu">
                <li><a href="#">Menu Option 1</a>

                </li>
                <li><a href="#">Menu Option 2</a>

                </li>
            </ul>
        </div>
    </div>
    <div class="content">
        <p>content goes here</p>
    </div>

    <div class="content">
        <p>content goes here</p>
    </div>
</div>

CSS

.box {
    width: 400px;
    height: 200px;
    margin: 5px;
    float: left;
    background: LightGray;
    border: 1px solid DarkGray;
    overflow: hidden;
}
.top {
    width: 100%;
    height: 25px;
    background: lightblue;
}
.icon {
    float: right;
    background: red;
    height: 15px;
    width: 15px;
    margin: 5px;
}
.menubox {
    float: right;
    background: yellow;
    position: relative;
    z-index:100;
    width: 150px;
}
.content {
    width: 180px;
    height: 165px;
    margin: 0px 10px 47px;
    float: left;
    position: relative;
    z-index: 0;
    display: block;
    background:DarkGray;
}
li {
    list-style-type: none;
    text-decoration: none;
}
ul {
    margin:none;
    padding:none;
}

JS/jQuery

$('.icon').mouseover(function () {
    $(".menu").show();
}); //toggle menu on hover
$(".menu").mouseleave(function () {
    $(this).hide();
});

Answer №1

why not try using position: absolute here? Check out the fiddle

.menubox {
    float: right;
    background: yellow;
    position: relative;
    z-index:100;
    width: 150px;
    top: 25px;
    right: 5px;
    position: absolute;
}
.box {
    width: 400px;
    height: 200px;
    margin: 5px;
    float: left;
    background: LightGray;
    border: 1px solid DarkGray;
    overflow: hidden;
    position: relative; /* make sure to add this line */
}

Edit: adjusted positioning for better results

Answer №2

To ensure that the yellow menubox does not disrupt the document flow, it should be positioned absolutely.

Add position:absolute; to the menubox CSS.

Additionally, set position:relative for the .box element so that the menu is positioned relative to it.

I have updated your fiddle for you:

http://jsfiddle.net/DdRmK/15/

Answer №3

Hey there, I've made some improvements to your code. Feel free to check it out at the following link: "jsfiddle.net/CcVnL/10/"

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

Send multiple form submissions using JQuery Ajax without needing to refresh the page

I am facing an issue with my form submission using Ajax. After receiving a response in the form of another form, when I try to submit it again using the submit button, it doesn't go through Ajax and uses the normal method instead. Why is this happenin ...

Get the input tag's value prior to submitting the form

After the user enters a number into an input tag in my HTML code, I need to immediately retrieve that value for mathematical calculations. I intend to use the "onchange" form event to trigger a PHP function responsible for performing the calculation before ...

Sending parameters to a personalized Angular directive

I am currently facing a challenge in creating an Angular directive as I am unable to pass the necessary parameters for displaying it. The directive code looks like this: (function () { "use strict"; angular.module("customDirectives", []) .directive ...

Exploring the nesting of client components in Next.jsIf you are

Exploring the realm of NextJS and React, I find myself delving into the realm of client components. One such client component I'm working with is called Form.jsx. It looks something like this: export default function FormHome() { ... a plethora of ...

Strangely glitchy navigation bar using jQuery

Over at this website, there's a top navbar that shrinks using jQuery when scrollTop exceeds 100px. The functionality works as intended, but there's an annoying stutter issue where the navbar starts jumping up and down erratically after slight scr ...

Dynamically adjust the gage value

Currently, I am working on a fitness application that involves showcasing BMI data using a gauge. However, I am struggling to figure out how to dynamically change the value of the gauge. In addition, when trying to implement the gauge script on button cl ...

Display the users in the appropriate div using socket.io technology

As a newcomer to express and socket.io, I am working on creating a website with the following features: The objective of the website is: Users can connect to the website and enter their username They are required to choose a column where they want to wri ...

Tips on changing font color within an email body in Outlook using a C#.NET Windows application

While working on a c#.net windows application, I encountered an issue with setting font color for specific lines in the email body when sending mail to Outlook. Despite trying various methods, I was unable to find a solution. Below is a snippet of my code: ...

Dygraphs: Utilizing two y-axes in a single series

I'm interested in plotting a single series with two synchronized y-axes that display different units, such as °F and °C temperatures. I want the data to be readable from both axes, but only one set of points should be plotted. Here are some approac ...

Utilize JavaScript to append elements to an array in each loop iteration, gradually building a single, unified

I find myself in a situation where an async request is sending data to a child react component. Upon logging the "data" in the component, I receive multiple arrays sequentially. Ideally, I would prefer not to rewrite the request in the parent component and ...

Sending data through the backbone form?

Whenever the submit button is clicked, a post request should be made to the server with input data and it will return a JSON object. I am unsure where to define the success function and how to receive the response object. Is this the correct way to call a ...

Different option for animated side slider based on location

Whenever I click on this div, it slides out smoothly. Check out these images to get a visual of what I am aiming for: This is how the Div looks when collapsed by default https://i.stack.imgur.com/zJIsA.png Once slid out, the Div looks like this (highlig ...

Could not add metric widgets in Ambari

Having trouble adding metrics widgets for a component I created in Ambari. Any help would be appreciated... Running Ambari version 2.5.2 and encountered the following errors: On opening the component page: app.js:66933 Uncaught TypeError: Cannot read p ...

Node.js Error: The requested URL cannot be found

I have encountered an issue in my Node project where I am getting a 'Cannot GET/' error when trying to open localhost on port 8081. I suspect that the problem lies in correctly reading the HTML file, but I'm not entirely sure. var express = ...

The AJAX calendar control remains unchanged after a reset

I am currently facing an issue with my ajax calendar control used in a form for selecting dates. The problem arises when I select a date from the previous year and then click on the reset button. Even though the text box is cleared, the calendar control s ...

Troubleshooting Issue with Formidable Not Working with Multer

Attempting to develop a webpage that enables users to upload a file to a designated folder while specifying a number in an input field. Currently, I am navigating through the Multer library despite typically using body-parser. Referencing both my app.js an ...

The Jquery script is ineffective for newly added elements

After creating an Ajax Form that functions well, I noticed that when the result of the form is another form, my script does not work for the new form generated. Is there a way to make the new form function like the old one? $(document).ready(function() ...

Switch between input and the input is not displayed inline

I've been struggling to align the Toggle button with the input box for quite some time now. I really need them to be inline so that they form a grid properly as everything is dynamic. I have experimented with using a Div on its own instead of a label ...

What is the best way to create a JavaScript Up/Down Numeric input box using jQuery?

So, I have this Numeric input box with Up/Down buttons: HTML Markup: <div class="rotatortextbox"> <asp:TextBox ID="txtrunningtimeforfirstlot" ClientIDMode="Static" runat="server">0</asp:TextBox> (In mins) </div> <div cl ...

Retrieving data from the firebase database by filtering based on the child's specific value

Looking at the firebase database, I can see that only the 'name' field is available. Now, I am trying to retrieve the 'quantity' value associated with that specific 'name'. Can someone provide me with a sample firebase query i ...