sophisticated HTML navigation bar

I am looking for a way to create a menu where the drop-down items overlay the rest of the menu when the screen width is small.

Here is my current code:

nav{
line-height:100%;
opacity:.9;
}nav ul{
background: #999;
 padding: 0px;
border-radius: 20px;  
list-style: none;
position: relative;
display: inline-table;
}nav ul ul{
display: none;
background: #567;
border-radius: 0px;
padding: 0px;
position: absolute;
top: 100%;
}nav ul li{
float: left;
}nav ul li a{
display: block;
padding: 25px 40px;
color: #666;
text-decoration: none;
}nav ul li:hover{
background: #345;
}nav ul li:hover a{
color: #fff;
}nav ul li:hover>ul{
display: block;
}nav ul ul li{
float: none; 
border-top: 1px solid #567;
border-bottom: 1px solid #678;
position: relative;
}nav ul ul li a{
padding: 15px 40px;
color: #fff;
}nav ul ul li a:hover{
background: #456;
}nav ul ul ul{
position: absolute; left: 100%; top:0;
}
<!DOCTYPE html>
<html>

<body>

<nav>
<ul>
<h3>
<li><a href="otherpage.html">Home</a></li>
<li><a href="otherpage.html">Page2</a>
<ul>
<li><a href="otherpage.html">Page2.1</a></li>
<li><a href="otherpage.html">Page2.2</a></li>
<li><a href="otherpage.html">Page2.3</a>
<ul>
<li><a href="otherpage.html">Page2.3.1</a></li>
<li><a href="otherpage.html">Page2.3.2</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="otherpage.html">Page3</a>
<ul>
<li><a href="otherpage.html">Page3.1</a></li>
<li><a href="otherpage.html">Page3.2</a></li>
</ul>
</li>
<li><a href="otherpage.html">Page4</a></li>
</h3>
</ul>
</nav>

</body>

</html>

I want a navigation menu that maintains my current design but allows the dropdown items to appear above the other menu items at a reduced width. Something similar to this example how to set css width equal to length of longest text.

I am not sure if achieving this would involve using JavaScript. While I would appreciate a JavaScript dropdown effect like the one in the link, it is not necessary.

If my issue is unclear, please try running my code in fullscreen mode and then decrease the browser width so you can see that the dropdown may become unclickable.

Also, it would be great if the text spacing remains consistent as the width changes.

Thank you!

Answer №1

If you're a fan of bootstrap, here's a brief introduction for you.

Bootstrap (front-end framework) is a valuable collection of tools that aid in the creation of websites and web applications. It offers design templates based on HTML and CSS for elements like typography, forms, buttons, navigation, and other interface components. Additionally, there are optional JavaScript extensions available.

To utilize its features, make sure to include these paths in your code:

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>

You can also download bootstrap from here.

Explore the various components offered by bootstrap here

For further insight, consider researching more about it through Google search.

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

Finding the common dates between two date arrays in Node.js

Looking for help with correctly intersecting matrices while working in nodejs? Trying to compare two arrays to find common elements, also known as an "array intersection." This seems to be a common question, and despite trying various solutions mentioned o ...

What sets the target property of the mousewheel event apart from other events like click, mousedown, and touchstart?

The mousewheel event's target property reveals the DOM element currently being hovered over when using the mousewheel or gesture-capable touchpad. In my experience (specifically in Safari 6, I will verify this in other browsers later), the target ret ...

Having trouble with the dropdown onclick event not triggering when an item is selected in React?

I am having an issue where the onclick event handler is not being called when a dropdown item is selected. In my code, I am generating a dropdown inside a loop in the componentDidMount() lifecycle method. I am passing an event handler function named "show ...

Deciphering HTML utilizing XSLT

Looking for assistance in extracting data from the following RSS feed: <rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"> <channel> <title>This is a test</title> <link>http://somelink.html</link> ...

Middleware for enabling the Cross-Origin Resource Sharing (CORS) functionality to efficiently manage preflight

My CORS configuration is set up globally to handle credentials like this: app.use(cors({ origin: 'https://example.com', credentials: true })) However, there are certain routes where I need to allow OPTIONS requests. Following the documentation, ...

I am trying to confirm in PHP whether any of the gender checkboxes have been selected. However, the code I have tried so far does not appear to be functioning as expected

Please refrain from suggesting the use of checked = "checked" in HTML, as the validation must be performed in PHP as per the requirements of my assignment. PHP Code: if (isset($_POST["gender"])) { $gender = $_POST["gender"]; if (($gender != "male") || ( ...

Enable the ability to input a value of -1 by clicking on a button or link, but only allow it once (the first click) without needing to disable the button or

I am working with the following script: <script language=javascript> function process(v){ var value = parseInt(document.getElementById('v').value); value += v; document.getElementById('v').value = valu ...

A guide to updating a particular row and sending parameters with jQuery and AJAX

I am utilizing a JSON response to dynamically display table content. Here is the code I am using to display row values: var rows = ''; for(var i=0; i<response.response.length; i++) { rows += '<tr><td class="country">&ap ...

Refreshing JqGrid tables after making changes and saving a row

In my PHP file, I have 4 jqGrid tables where I pass a different JSON array for each table. The data displayed on the grids come from one table with various SQL conditions. I am using inline editing for all the grids. After editing and saving a row in tabl ...

What is the best way to transfer the "user" object from TopBar.js to App.js in my project?

In my project, TopBar.js functions as an AppBar component responsible for handling user authentication. When a user logs in, I receive an object called "user". My goal is to export this "user" object to App.js. If I am successful in exporting it to App.js ...

Infinite scroll causing Firebase ".length" function malfunction

My NextJs website is encountering errors related to Firebase infinite scroll. The issue seems to be with the .length property being undefined for some unknown reason. I am struggling to debug the code and make it work properly in Next.js. Any help would be ...

Apply styles specifically to elements that contain a child element

I have a scenario where there are multiple <p> elements with the same class names, but only one of them has a child element. My objective is to highlight only the <p> that contains a child, however, my current code ends up highlighting all of t ...

I'm looking for a way to convert an array value to JSON using jQuery

i need assistance in converting an array value into json format. An example is provided below: Sample Array [Management Portal!@!@Production Issue Handling!@!@/IONSWeb/refDataManagement/searchDynamicScripts.do, Management Portal!@!@ Event Browser!@!@/ION ...

Sending a variable from JavaScript to an external PHP file

There are numerous questions on similar topics, but I'm struggling to figure it out, my apologies. I have a file containing some JavaScript variables that depend on user input (without using a form) and a normal HTML link to my PHP file. <script& ...

Ways to capture targeted requests

Utilizing NestJS and Angular 2, I have noticed that both frameworks have a similar approach when it comes to working with Interceptors. I am currently looking for the best practice to identify specific requests in order to perform additional tasks. When d ...

Button group malfunctions on smaller screens

After integrating a button group into my new website, I noticed that the first two buttons stop functioning properly on smaller screens. Surprisingly, if I remove the text-center div, all buttons cease to work entirely. Despite attempting various solution ...

Automatically insert personalized CSS design markers into Material-UI elements using code

Within my react-redux app, I am utilizing material-ui components. The initial UI prototype was established using adobe-xd, which has the capability to export character styles (design tokens) in a CSS file format: :root { /* Colors: */ --text-color: #F8E29 ...

Choose all the checkboxes alongside the markers on Google Maps

On this page , I have included a checkbox labeled "Select All" at the bottom, which automatically checks all other checkboxes. Although the code below achieves what I want, the marker icons are not showing up. How can this be fixed? $(document).ready(func ...

Tips for applying a jQuery class when the page is both scrolled and clicked

As I work on building a HTML website, I encountered an interesting challenge. I want to create a dynamic feature where, as users scroll through the page, certain sections are highlighted in the navigation menu based on their view. While I have managed to a ...

Using PHP and JavaScript to enhance functionality around a hyperlink

I am trying to incorporate a small piece of Javascript on my website to ensure user confirmation. While I have successfully used the 'onclick' function with buttons, I am facing difficulty implementing it on a link. Here is the link in question: ...