Crafting a horizontal sub-menu that sits between the parent element and the company logo

Seeking assistance with designing a navigation menu that places the navigation bar above the site logo. I envision the sub-menu expanding horizontally from the navigation bar and positioning itself between the parent navigation bar and the logo.

  • The sub-menu expands horizontally
  • The logo is positioned below the collapsed navigation bar
  • The sub-menu will expand out of the navigation bar, pushing down the position of the logo

Main navigation:

<nav>
    <div class="container">
        <ul class="menu">
            <li> <a href="#">One</a>

                <ul class="sub-menu">
                    <li><a href="#">Sub Menu One</a>
                    </li>
                    <li><a href="#">Sub Menu Two</a>
                    </li>
                    <li><a href="#">Sub Menu Three</a>
                    </li>
                    <li><a href="#">Sub Menu Four</a>
                    </li>
                    <li><a href="#">Sub Menu Five</a>
                    </li>
                </ul>
            </li>
            <li> <a href="#">Two</a>
            </li>
            <li> <a href="#">Three</a>
            </li>
            <li> <a href="#">Four</a>
            </li>
            <li> <a href="#">Five</a>
            </li>
        </ul>
        </div>
    </div>
</nav>
<div class="logo"></div>

An example showcasing this concept can be found here: http://jsfiddle.net/GSfpj/11/, along with the CSS code used.

Instead of having the sub-menu expand under the logo, my goal is to push the logo downwards and place the sub-menu between the parent navigation and the logo.

If possible, I would like to achieve this using only CSS. Any guidance on how to accomplish this would be highly appreciated :)

Answer №1

One potential solution could involve implementing the following CSS code:

.submenu:hover {padding-bottom:20px;}

However, personally, I find this approach to be less than ideal. Have you considered having the sub menu display on top of the logo instead?

Answer №2

Check out this live example: http://jsfiddle.net/GSfpj/27/

However, there are a few drawbacks to consider:

  1. The need to remove sub-menus from the DOM layout leads to setting them to position: absolute, requiring specified heights and making it less reusable.
  2. If <li>s are positioned relative, extra space appears before the sub-menu. Positioning relative to the parent <ul> may cause overlap issues with the :hover state.
  3. Lack of dynamic layout results in blank space when hovering over an item without a submenu.

To address these challenges, JavaScript or alternative markup solutions (like adding classes based on submenu presence) may be necessary.

Despite its limitations, the solution works, so use it as needed.

Answer №3

Here is the updated link to your code snippet. Make sure to modify the following CSS:

ul.menu li {
    display:inline-block;
    padding:15px;
    position:relative;
    z-index:9999;
}
ul.menu li ul.sub-menu {
    position:absolute;
    margin:0;
    padding:0;
    background:#2f2f2f;
    width:300px;
}

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

Determining height of an element in AngularJS directive prior to rendering the view

As I dive into the world of Angular, any assistance is greatly welcomed. My goal is to vertically align a div based on screen size (excluding the header and footer) when the page loads, the window resizes, and during a custom event triggered by the user ex ...

Carousel with Bootstrap: Heading positioned over the content

My goal is to have the caption of Bootstrap Carousel displayed above the content, but I'm encountering issues with it. When clicking on the chevrons, you may notice the < Item 1 > bouncing... (This behavior is a bug, and logically speaking, I ex ...

Creating a Full-Width Form Using Bootstrap

I need help aligning 3 form boxes side by side with a total width of 100%. I want to be able to specify the width of each box, or have the last two boxes set to their default size while the first box fills up the remaining space. Here is my current code: ...

What are the steps for distributing a styled React component?

My goal is to release a UI library using React, but I am struggling with how to handle styles. When I write code in a project, I typically use webpack and babel to build my code, resulting in the creation of a *.css file. import React from 'react&ap ...

Seeking out all (including potentially relative) URLs on a webpage: Possible strategies to consider

For a coding challenge, I am working on a small python tool to download an entire website locally. In order to view the website offline, I need to convert all URLs to relative URLs. This is necessary to ensure that resource files (such as .js and .css) are ...

The image source is not functioning properly to display the image, even though it is working perfectly on

I'm currently attempting to retrieve an image from Instagram. Everything seems to be in order with the image link on Instagram. However, when I try to use it within an img tag, it fails to fetch. One thing worth noting is that this particular image d ...

Using Express, Node, and JQuery to handle form submissions

I am struggling with form submissions while working on a web app using HTML, Express, and Node.js. Despite being new to these technologies, I have created a script that generates a dynamic form based on certain factors: $FormContainer.html(''); ...

Go to the identical page with a message embedded in it

Creating a login page using JSP involves an index.jsp file which contains the form and javascript scriplets. The connectivity to an Oracle database and validation of username and password are handled in check1.jsp. The problem arises after entering the us ...

Increase or decrease the quantity of items by cloning with Jquery and dynamically changing the ID

Currently, I am working on a jQuery clone project where I need to dynamically add and delete rows. Despite searching extensively on Stack Overflow and Google, I only have a basic understanding of how jQuery clone works. Any suggestions would be greatly ap ...

Refreshing the page after executing a MySQL UPDATE statement

There seems to be a problem with the page refreshing faster than the query execution. I have an UPDATE query to update my database with values in my fields, triggered by pushing a button. However, upon clicking the button (which refreshes the website), th ...

Executing Javascript code from a specified web address

Let's say I have an image that needs to be shifted vertically, and I achieve it using the following code snippet: document.getElementById('ImgID1').style.verticalAlign = However, the value by which I need to shift the image is provided thr ...

How to integrate VLC media player into an HTML webpage

I'm currently struggling to incorporate a VLC player into a website. What is the most effective method to achieve this task? I need to stream a video file using VLC and display it on the webpage for other users who are logged into my site to view. I&a ...

The latest version of npm Boostrap (4.1.0) is missing some important CSS properties for the `background` tag

I am currently working on an Angular 5.2.10 project that utilizes angular-cli and bootstrap version: 4.0.0-beta.2 with a specific css class called .en-icon-24: .en-icon-24 { background: url(../../../../assets/img/icons.png) -370px 0px; width: 24 ...

s3 key not found, The specified key does not exist. previewing file from a web link

After utilizing paperclip and s3, I successfully uploaded a word document and now I am seeking the ability to preview it directly from the database using an iframe. https://i.stack.imgur.com/ceCPu.png <iframe src="<%= agreement.document.url(:smal ...

Iterate endlessly over CSS styles in Angular 4

I'm looking to create a website background 'screensaver' by looping through an array of background URLs with a delay between switches. Currently, I have the array stored in my .ts file and I am using the NgFor directive in my HTML. However, ...

Navigation menu that is vertical and includes submenus, where the parent list item remains active even when visiting subpages

I'm currently utilizing Jekyll and Compass to construct an interactive prototype. Within one of my includes, I've implemented a sidebar navigation. The challenge arises when dealing with submenu items, as the active class on the parent (li) does ...

How to temporarily disable CSS hover effects

I have a menu with some links <ul id="nav"> <li> <a href="#">Project</a> <div class="subs"> <div> <ul> <li> <h3>Save</h3> <ul> <li> <a i ...

JavaScript Issue Causing Jquery Carousel Dysfunction

I am having trouble with the slider I created using JS Fiddle. The link to the slider is not working and I need some assistance. Click here for the slider <div class="row"> <div id="myCarousel" class="carousel slide vertical"> &l ...

The Ajax contact form is not submitting the necessary POST data to the PHP script

After creating an html form with ajax: function confirmSendMail() { $(".send_contact").click(function(event){ event.preventDefault(); var name = $("#inputName").val(); var email = $("#inputEmail").val(); var pho ...

Automatically resizing images in a canvas when their resolution exceeds the canvas size in HTML5

I am currently using Html5, fabric.js, and JavaScript to upload multiple images to a canvas. However, there are instances where the uploaded image size exceeds that of the canvas. I am looking for a way to ensure that the image is set to a fixed size. v ...