Aligning drop down menu links in a horizontal CSS menu with their respective parent elements

https://i.sstatic.net/JctLc.pngMy navigation bar has a full-width drop-down sub-menu (the "About" dropdown), but I am having difficulty aligning the links within the submenu directly under their parent. I also need this layout to be responsive, ensuring that the sub-links remain centered regardless of the viewport size.

Can anyone offer assistance in identifying my mistake or provide guidance on how to achieve this effect?

Thank you in advance for any assistance.

.navigation--main li:hover>ul {
  display: flex;
  justify-content: center;
}

ul.navigation--main li ul {
  background: #000;
  color: #fff;
  display: none;
  position: absolute;
  top: 114px;
  left: 0;
  width: 100%;
}

ul.navigation--main li ul li {
  padding: 1.5em 0.5em;
}
<div class="navigation--container">
  <div class="logo">
    <a href="#"><img src="assets/img/Group 85.svg" alt="ORRAA Logo" class="homeLogo" height="78.93" width="260" /></a>
  </div>
  <div class="navigation">
    <ul class="navigation--main">
      <li><a href="index.php">Home</a></li>
      <li><a href="about.php">About</a>
        <ul>
          <li>
            <a href=""></a>Ocean risk</li>
          <li>
            <a href=""></a>About ORRAA</li>
        </ul>
      </li>
      <li><a href="#">Membership</a></li>
      <li><a href="#">Governance</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
    <ul class="navigation--social-icons">
      <li>
        <a href="#"><img src="assets/img/facebook.svg" alt="facebook"></a>
      </li>
      <li>
        <a href="#"><img src="assets/img/instagram.svg" alt="instagram"></a>
      </li>
      <li>
        <a href="#"><img src="assets/img/Path 22.svg" alt="twitter"></a>
      </li>
    </ul>
  </div>
</div>

Answer №1

Feel free to make changes in the CSS file to customize the design. Hopefully, this solution will assist you.

.navigation--main li:hover>ul {
  display: flex;
  justify-content: center;
  width: calc(100vw - 112px);
}
.navigation--main li:hover>ul li{
  margin-left:20px;
}

ul.navigation--main li ul {
  background: $brand-sky-blue;
  display: none;
  width: 100%;
}

ul.navigation--main li ul li {
  padding:10px;
}

This code snippet serves as a useful reference point: codepen.io/arpita1030/pen/pMLQME

Answer №2

It's possible that I may have misunderstood, but here is my suggestion

.navigation--main li:hover > ul {
    display:flex;
    justify-content: center;
    position: static;
}

As a result of this code, the specified div now displays directly below the About navigation link, causing the other elements to be pushed down.

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

Possible Chrome Bug Affecting CSS Margin Issue?

Wondering if there might be a bug lurking in Chrome or if my CSS needs some tweaking. The issue at hand is that even though I've set a CSS declaration on .blockmenu li with margin: 2% !important, Chrome doesn't seem to be interpreting the percent ...

Stripping comments from certain automatically generated HTML could be necessary due to their potential invalidity when nested

Is there a way to efficiently remove HTML comments from dynamically generated content? I have tried using the regex /<!--(.*?)-->/ with the ? qualifier, which works for most cases. For example: <!-- <h1> test </h1> --> not remove &l ...

Develop a unique calculator application using Javascript and showcase the calculated result

I'm currently struggling with my JavaScript basic calculator project. I can't seem to get the calculations to display on the screen when I click the buttons. Although I am new to JavaScript, I've been trying hard to make sure that clicking ...

Can I split icons instead of combining them when stacking in Font Awesome?

Is it possible to stack icons by dividing their size instead of multiplying them? I am looking to have my first icon be the same size as the font I am using, and the icon on top of it to be half the font size. Can this be achieved with Font Awesome or do I ...

Tips for implementing validation in a multi-step form as outlined in w3schools tutorial

I came across a multistep form creation tutorial on w3schools. However, the tutorial only covers generic validation (checking if a field is empty), which is not sufficient for my needs. How can I implement HTML validation (e.g., min, max, length) for text ...

Showing the overflow scroll bar on both iOS and Android mobile devices

Is it possible to make the overflow scrollbar visible on mobile devices, specifically iPhones, Samsungs, and Safari browsers? The scrollbar is currently visible on desktops but not on mobile devices. I need a solution for this issue. Here is the current c ...

Unexpected JavaScript Bug (with jQuery)

I have an interesting code snippet that captures button clicks and then hides the existing content, revealing the content of the clicked item instead. This code is part of my init.js file along with other functionalities: $(function() { $('#conta ...

Data extracted from the range selector

Is there a way to take values and use them for hiding or displaying certain divs? I have been using jQuery Simple Slider for this purpose. I attempted the following code, but it did not work well. I want the div with id "3" to be visible when the slider ...

PHP Solution: I'm working on a page that is accessed using the post method. However, I need to defer the execution of certain code until after the page has finished

Apologies for the confusing title, but I'm struggling to succinctly explain my issue: I have a web page that is accessed through a button. When this button is clicked, specific data (a unique identification name) is sent to the page I want to view. Ho ...

Creating a table that adjusts its columns to match the same width percentages for a responsive design

Three tables were created with identical column names. The HTML markup for each table is consistent. When viewed on a laptop browser, the tables display correctly as depicted in this screenshot: https://i.sstatic.net/5BAdg.png However, when viewed on a s ...

Refreshing page using jQuery following an AJAX request

My script is functioning properly, however the use of location.reload(); does not seem to be effective. I am aiming to refresh the page after deselecting the last checkbox. $(".catcf, .coursetype, .yearcf, .manthcf, .venucf").on('click' ...

Employ gulp for rebasing CSS URLs

I have a question regarding how to resolve the following issue: In my sass files, I utilize absolute path variables in my main include files. For example, fonts are stored in /assets/fonts/... and icons are located in /assets/icons/... These paths only wo ...

What is the best method for selecting or deselecting all checkboxes except for one using a single checkbox in angularjs

$scope.checkAll = function() { if ($scope.selectedAll) { $scope.selectedAll = true; } else { $scope.selectedAll = false; } angular.forEach($scope.MyProducts, function(item) { item.Selected = $scope.selectedAll; }); /*});*/ } <di ...

What is the best way to interpret HTML special characters (such as those with accents) in a Facebook share post?

<meta property="og:title" content="<?php echo $title; /> where $title is retrieved from a database. The title should display as blácv with the character a accented, but when sharing the post on Facebook, it appears as bl&aacutecv. T ...

When faced with the scenario of having the hashtag in the href attribute and a browser's back button, it

Hello everyone, I've encountered an issue with the "back" action in my browser. When I click on a link, it takes me to a specific page due to a JavaScript function being called. However, when I hit the back button, it simply removes the "#" from the U ...

The Bootstrap form input control is not updating its background and border color as expected

Recently, I decided to revamp the look of the input controls on my website. I made some changes in the code like so: //Updating bootstrap variables $input-bg: $background-color; $input-color: yellow; $input-border-color: $gray-500; $input-focus-border-colo ...

App script: Extracting HTML form data from a web application

I have been trying to work on a script that involves taking input from an HTML form and processing that data in order to populate a Google Sheet. Unfortunately, I haven't had much success with it so far. Here is the code I have been working on: Index ...

Block with vertical text covering entire height

I need to place an additional block with 100% height and vertical text (bottom-to-top direction) inside a variable height block, aligning it to the left side without using width and height calculations in JS. Is there a way to achieve this using CSS transf ...

"Enhancing user experience: Rotating hamburger menu icons with a simple click

I'm facing an issue with my hamburger menu, specifically with the icons. Here's how my HTML is structured: <input type="checkbox" id="check"/> <header class="IndexHeader"> <nav class="navigat ...

Tips for efficiently exporting and handling data from a customizable table

I recently discovered an editable table feature on https://codepen.io/ashblue/pen/mCtuA While the editable table works perfectly for me, I have encountered a challenge when cloning the table and exporting its data. Below is the code snippet: // JavaScr ...