Designing a sideways expanding navigation bar

Currently, I am working on a project for my Information Technology coursework and struggling with creating a horizontal drop-down menu. If anyone has an example of such a menu that I could integrate into my site, I would greatly appreciate it! :D

<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'/>

<link rel="stylesheet" type="text/css" href="main.css" />
<link href='http://fonts.googleapis.com/css?family=Annie+Use+Your+Telescope' rel='stylesheet' type='text/css'>

</head>
<body>



<div id="header" style="font-family: A Sensible Armadillo; font-size: 28px; font-weight: 500;">
    <div id="nav">
        <a id="navicon" href="#menu">&#9776;Menu</a>
        <a id="dropdown" href="#about">About</a>
        <a id="dropdown" href="#portfolio">Portfolio</a>
        <a id="dropdown" href="#contact">Contact</a>
    </div>
</div>

<div id="page-wrap">

    <div id="page1">
        <a name="about"></a>
        <div class="page-padding"></div>

    </div>

    <div id="page2">
        <a name="portfolio"></a>
        <div class="page-padding"></div>

    </div> 

    <div id="page3">
        <a name="contact"></a> 
        <div class="page-padding"></div>

    </div>

</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
  function filterPath(string) {
    return string
      .replace(/^\//,'')  
      .replace(/(index|default).[a-zA-Z]{3,4}$/,'')  
      .replace(/\/$/,'');
  }
  $('a[href*=#]').each(function() {
    if (filterPath(location.pathname) == filterPath(this.pathname)
    && location.hostname == this.hostname
    && this.hash.replace(/#/,'')) {
      var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
      var $target = $targetId.length ? $targetId : $targetAnchor.length ?     $targetAnchor : false;
       if ($target) {
         var targetOffset = $target.offset().top;
         $(this).click(function() {
           $('html, body').animate({scrollTop: targetOffset}, 2000);
           return false;
         });
      }
    }
  });
});
</script>

</body>
</html>

The above HTML code is what I currently have. If needed, I can also provide the stylesheet for reference.

Thank you in advance for any assistance, Cro

Answer №1

If you're looking for navigation options, Bootstrap offers great support along with a variety of other features. Check out the details here.

Here is a basic example of how you can implement dropdown navigation in your code:

<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true>
Dropdown
<span class="caret"></span>
</button>
    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
        <li><a id="navicon" href="#menu">&#9776;Menu</a></li>
        <li><a id="dropdown" href="#about">About</a></li>
        <li><a id="dropdown" href="#portfolio">Portfolio</a></li>
        <li><a id="dropdown" href="#contact">Contact</a></li>
    </ul>
</div>

Remember to include these stylesheets and JavaScript along with your existing code:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet"    href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

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

What is the method to generate a response in the browser console by making jQuery ajax calls?

I have implemented a caching system for storing links in a database using a page crawler that utilizes jQuery to make ajax calls. Prior to making an ajax call to an external site, I ensure that the link provided belongs to one of the specified domains or h ...

Using Node.js to insert data into a database and receiving a response code of 0

Every time I send the following to this API: [ {"project_id": "knsfviv9", "coach_id": "" }, {"project_id": "ovsijiov9", "coach_id": "" } ] The data gets inserted into the database, however, the response variable remains at ...

Catch the return of the transition event

My website is built on asp net core, with all pages displayed as partialviews to create a spa model without relying on angular or other frameworks. By switching partialviews, I can easily modify the page's url using window.history.pushState ("objec ...

Remove the post by utilizing the $.ajax function

I am just starting out with using $.ajax and I'm not very familiar with it. I have a button that is meant to delete a user post based on the article ID provided. <button type="button" onclick="submitdata();">Delete</button> When this but ...

uploading files and data using formData in jquery without the need for a form in asp.net

(...) UPDATE: // Front end var $elem = $("a.attachMessageBtn"); var evtOnClick = $elem.attr('onclick'); var postData = new FormData(); postData.append("FID", FID); postData.append("messageText", messageToSend); for (var i = 0; i < files.le ...

Displaying Props Information in a Modal Window using React

Currently venturing into the realm of React JS, where I am in the process of developing a sample eCommerce application for real-time use. However, I have hit a roadblock. In my Products List, there is a Buy button for each product. When clicking on this b ...

Error encountered at line 51, column 7 in the script (vm.js) while executing JavaScript code for a Discord bot

When I run node index.js, I encounter an error. Here is the code: const botconfig = require("./botconfig.json"); const Discord = require("discord.js"); const bot = new Discord.Client({disableEveryone: true}); bot.on("ready", async () => { console.log ...

Preserve present condition following a jQuery click event

I'm facing a challenge where I need to hide a button upon clicking another button, but the problem is that when the page refreshes, the hidden button becomes visible again. My objective is to keep it hidden even after refreshing the page and only reve ...

What is the method of invoking the HTML5 form.checkValidity function within a WebForms form.onSubmit event?

When trying to integrate HTML5 input types into an ASP.net WebForms website, how can one extend or override the standard WebForms WebForm_OnSubmit JavaScript function? Most user-agents (e.g. Chrome, IE, Firefox) are already equipped to handle tasks like d ...

CSS for leaving white space at the end of one third of a container

Currently developing a website and facing an issue with the layout: I am trying to create 3 columns of equal height with each column taking up one-third of the width. However, there seems to be a small white gap on the right side of the last column. Here ...

Using AngularJS client and Flask server for a RESTful call, one can include the

I am currently facing an issue where I need to send a REST request from my AngularJs client to a Flask server. The problem arises when one of the ids (key) in the request contains a forward slash. Interestingly, if the key does not contain a slash, the re ...

How can I add a comma after every third number in a react component?

I am currently developing an input feature where I need to insert a comma after every 3 numbers, such as (352,353,353). The challenge is to display this format in a text field. Since I am new to working with React, I would appreciate any guidance on how to ...

What is the best way to extract data from a JavaScript object in C++?

I have integrated an IE ActiveX control within my C++ (MFC) application. This embedded IE contains a JavaScript method that sends data back to my C++ application using the following simplified JavaScript code: function passDataTocpp() { return {ke ...

VueTablePlus dropdown filter options for Vue.js version 2

I am facing an issue with populating dropdown options on vue good table. My approach involves making an API call to fetch the possible values for the dropdown and then assigning them to the column filter. However, I am struggling to make it work. <vue ...

Is there an automatic culling feature in Three.js that hides objects not currently in view behind other objects?

If that's not possible, is there an alternative method? For instance https://i.sstatic.net/Vd1IX.png ...

Utilizing the ref received from the Composition API within the Options API

My current approach involves utilizing a setup() method to bring in an external component that exclusively supports the Options API. Once I have imported this component, I need to set it up using the Options API data. The challenge I face is accessing the ...

Create an interactive Angular form that dynamically generates groups of form elements based on data pulled from

I am currently developing an Angular application and working on creating a dynamic form using Angular. In this project, I am attempting to divide the form into two sections: Person Name and Personal Details. While I have successfully grouped fields for P ...

Having trouble defining the image path with jQuery in Codeigniter

When using jQuery to set the image path in the success section of an ajax call, I encountered an issue. The structure of my image folder is as follows: Project name | -application -system -user_guide -image | -img_412.png The image path was set ...

Is there a way to use @include_once in PHP for content that is loaded dynamically

Incorporating a header.php file into all necessary pages is causing it to display twice because of the method used. By utilizing @include_once('header.php');, AJAX can load the page into the "container" div without duplication concerns. However, ...

Tips for creating a fixed top drop-down menu using CSS

Looking to create a dropdown menu similar to the one found on , using only CSS without jQuery, specifically for the "All" category menu. I have attempted a CSS dropdown menu but struggling to keep the second level menu fixed at the top. Any suggestions w ...