Arrange the child elements of a div to be displayed on top of one another in an HTML document

I am struggling with a div containing code

.popupClass {
    width: 632px;
    height: 210px;
    position: absolute; 
    bottom:0;
    margin-bottom: 60px;
}
    <div class="popupClass">
         <div style="margin-left: 90px; width: 184px; height: 210px; position:relative; z-index:1"  id="mainMenuDiv" hidden>
             <img style="z-index:2;" id="menu" src="images/popup.png" width="184" height= "210" alt="menu_btn"/>
             <a href="categories.php" style="bottom:-80px;" >Categories</a>
             <ul>
                  <li><a href="categories.php" >Categories</a></li>
                  <li><a href="about.php" >About Us</a></li>
             </ul>
         </div>

         <div style="margin-left: 190px; width: 184px;" id="shareDiv" hidden>
             <img id="menu" style="margin-left: 90px" class="clicker" src="images/popup.png" width="184" height= "210" alt="menu_btn"/>
         </div>

         <div id="dDiv" hidden>
             <img id="menu" style="margin-left: 90px" class="clicker" src="images/popup.png" width="184" height= "210" alt="menu_btn"/>
         </div>

     </div>

I am facing an issue where I need the ul element to appear on top of the image, without being added to the background of the div which could lead to cropping due to the div settings. How can I accomplish this?

Answer №1

Here is the code snippet for your desired layout:

<div style="margin-left: 90px; width: 184px; height: 210px; " id="mainMenuDiv">
   <img style="position:absolute;z-index:1; top:80px" id="menu" src="http://placehold.it/350x150"/>
   <ul style="position:absolute;z-index:2;">
      <li><a href="categories.php" >Categories</a></li>
      <li><a href="about.php" >About Us</a></li>
   </ul>
</div>   

EDIT:

If you are looking to simplify your markup, here's an updated version of your code that achieves the same result with a bit more streamlined structure:

<div class="popupClass">
    <img id="menu" src="http://placehold.it/350x150" alt="menu_btn" />
    <div id="menuWrapper">
        <a href="categories.php" class="link">Categories</a>
        <ul>
            <li>
                <a href="categories.php">Categories</a>
            </li>
            <li>
                <a href="about.php">About Us</a>
            </li>
        </ul>
    </div>
</div>   

CSS:

#menu {
    width:184px;
    height:210px;
}
#menuWrapper {
    position:absolute;
    top:50px;
    left:30px;
}
.link {
    display:block;
}   

The CSS can be externalized for better maintenance. Essentially, the menu items are wrapped in a div container and positioned absolutely within its parent element, allowing for easy alignment adjustments using positioning properties. If this setup suits your needs, great! If not, feel free to provide feedback for further modifications.

Answer №2

It seems like you are looking to achieve something similar to this:

<div style="position: relative">
  <img style="position:absolute;z-index:1"/>
  <ul style="position:absolute;z-index:100">
    <li><a href="categories.php">Categories</a></li>
    <li><a href="about.php">About Us</a></li>
  </ul>
</div>

To customize the positioning, you can adjust the top/left/bottom/right values of the ul accordingly.

Check out this fiddle for a live demo.

I hope this information proves helpful.

Answer №3

Consider utilizing the position property in this way:

<img style="position:relative;z-index:1" id="menu" src="images/popup.png" .../>
<ul style="position:relative;z-index:2">
   <li><a href="categories.php" >Categories</a></li>
   <li><a href="about.php" >About Us</a></li>
</ul>

You have the option to use position: relative/absolute/static/fixed based on your design requirements

If you prefer a background display, consider using backgroud-image for the ul instead of a separate img tag

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

Set the style to be displayed as a block element

I am working on a Rails application that contains some <li> elements with the CSS property display: none;. I want these elements to only appear on the page when they are being dragged. However, there are some elements that do not have the display: no ...

Excessive gap located above the section element

On the web page I'm practicing with, I've noticed an unwanted space at the top of the "Favorite Food" section. To center my unordered list, I made the "section" elements inline-block, but this created the issue. How can I remove that space at the ...

Is the ClientScriptmanager operational during a partial postback?

After successfully completing an ASP.NET operation, I want to automatically close the browser window. The following code is executed by a button within an Ajax UpdatePanel: Page.ClientScript.RegisterClientScriptBlock(typeof(LeaveApproval), "ShowSuccess", ...

The Jquery .change() function refreshes the results just once

I am working on a form with 3 input fields named #first, #second, and #third, along with a fourth field labeled as #theResult. <div id="addFields"> <span id="addFieldsHeader">Add The Fields</span> <table style="margin:0 auto;"> ...

How to resolve CORS error when using custom request header in Django with JavaScript and redirecting to OPTIONS request?

I am currently working on building an API library using Django. This API will be accessed by javascript, with the Django-API and javascript running on separate servers. The Django API library requires a custom request header from the javascript front end, ...

Leveraging Global SCSS Variables in Next.JS with SASS

In my Next.js Application, I have a global CSS file named main.scss imported in the pages/_app.js file. _app.js import '../global-styles/main.scss' export default function MyApp({ Component, pageProps }) { return <Component {...pageProps} ...

Storing text entered into a textarea using PHP

In a PHP page, I have a textarea and I want to save its content on click of a save button. The insert queries are in another PHP page. How can I save the content without refreshing the page? My initial thought was using Ajax, but I am unsure if it is saf ...

What is the best way to retrieve a response from a modal dialog using jQuery?

Is there a way to utilize an add-in such as simple-modal or the dialog add-in in the UI kit to achieve AJAX interaction with the server? I am looking for a solution that allows the modal to communicate with the server and return the result back to the ca ...

AJAX isn't quite cooperating - it seems that only the error callback is getting

Even though I have specified both success and error callbacks, the error callback is being triggered even when the status code is 200. In addition, I am also making a curl call to another php file within registry.php. This is what I have attempted: $.aj ...

Eliminating the table header in the absence of any rows

I have successfully implemented a Bootstrap table in my React application, where users can add or delete rows by clicking on specific buttons. However, I want to hide the table header when there are no rows present in the table. Can anyone guide me on how ...

What is the best way to send a List in the model as a parameter for an AJAX request?

I'm currently using MVC 4 ASP.net with Razor views and I have an issue with refining my search results using AJAX calls. The current approach involves creating methods in the controller that include all the search filters, which has resulted in a meth ...

The Javascript function will keep on executing long after it has been invoked

I am currently facing an issue with calling a JavaScript function within an AJAX call. The progress function below is supposed to be executed every time the for loop runs. However, the problem is that although progress is being run as many times as the for ...

IE displaying "slow script" alert due to Knockout malfunction

Within my grid of observables and computed observables, the first row serves as a multiplier for all subsequent rows. Users can modify this percentage rate and Knockout automatically updates all relevant values accordingly. Additionally, I require a textbo ...

Node and Web scraping Promise: a powerful combination

I've been using Cheerio and Node for web scraping, and I thought implementing promises could simplify handling asynchronous code. However, my attempt to chain promises hasn't been successful. Below is the code I'm working with, in hopes that ...

In Internet Explorer, regardless of how much scrolling occurs, the document.body.scrollTop property will consistently be

While moving the mouse, I'm showing the value of document.body.scrollTop in the status bar. However, I have noticed that this value is consistently 0 in Internet Explorer. Why is it always 0 in IE? Is there an alternative method to determine how far t ...

What is the best way to activate a function within an npm package in a Vue application?

I'm just starting out with Vuejs and I've recently installed the vue-countup-v2 npm package. I successfully imported it into my Vue component and noticed that it works perfectly when the page loads. However, I am interested in triggering the Coun ...

Creating a larger spinning div using CSS3 animation

I am looking to add a fun hover effect to my div where it spins and zooms in at the same time. Here is what I have so far: [html] div class="myMsg">> <p id="welly" style="color: #009">Welcome to Y3!<br><br><br>T ...

How can the Jquery UI Datepicker value be automatically set upon redirecting to this page?

When I submit a form and an error occurs, the value selected in the datepicker is not retained. The datepicker field remains empty. How is this possible? <html> <head> <script type="text/javascript" >. $(function() { ...

Is manually coding HTML for email necessary, or are there any practical tools or converters available?

Creating HTML emails is a different challenge compared to designing websites, as it requires working with tables instead of CSS. I'm in need of recommendations for tools specifically designed for HTML email creation, preferably from individuals who h ...

What is the best way to retrieve the unique identifier of dynamically created divs and showcase a message based on that identifier?

Is it possible to retrieve the id of a dynamically generated div and show a unique message when each div is clicked in the code snippet found at this link? function get_random_color() { var letters = '0123456789ABCDEF'.split(''); ...