Utilizing HTML and Bootstrap to create a collapsible dropdown menu

Is there a way to collapse just the dropdown menu in a navbar into a hamburger icon on small screens, rather than the entire navbar?

Example: https://i.sstatic.net/bDxio.png

Answer №1

Here is a method you can use

Bootply link

CSS styles

@media screen and (max-width: 768px) {
  #mymenu{
    background-color: #f8f8f8;
  }
  .navbar-header{
      display: inline-block;
      z-index: 2;
      position: absolute

    }
  .navbar-right{
    z-index:1
    position:absolute;
    width:100%;
    top:0;
    left:0;
    margin-top:0;
    }
}
.navbar-toggle{display: block !important;}

HTML structure

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">Brand</a>
    </div>

      <ul class="nav navbar-nav navbar-right">
        <li class="dropdown">
          <button type="button" id="mybtn" class="dropdown-toggle navbar-toggle collapsed" data-toggle="dropdown" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar visible-xs"></span>
          <span class="icon-bar visible-xs"></span>
          <span class="icon-bar visible-xs"></span>
            <span class="hidden-xs">Toggle</span>   
        </button>

          <ul class="dropdown-menu" id="mymenu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li role="separator" class="divider"></li>
            <li><a href="#">Separated link</a></li>
          </ul>
        </li>
      </ul>
  </div><!-- /.container-fluid -->
</nav>

Dropdown functionality included

Check out this Bootply example

Addition to CSS for Dropdown effect

@media screen and (max-width: 768px) {
  #mymenu{
    background-color: #f8f8f8;
  }
  .navbar-header{
      display: inline-block;
      z-index: 2;
      position: absolute

    }
  .navbar-right{
    z-index:1;
    position:absolute;
    top:0;
    right:15px;
    margin-top:0;
    }
}
    .navbar-toggle{display: block !important;}

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

Angular JS manifesting a nested JSON filter system

As a newcomer to AngularJS, I am trying to implement a filter in my ng-repeat. Here is the structure of my JSON data: var data = [ {name:test1,b1:{lastValue:0},b2:{lastValue:6},b3:{lastValue:6},b4:{lastValue:0}} {name:test2,b1:{lastValue:6},b2:{l ...

I am looking to showcase the JSON output on a ReactJS interface

Here is the output of my JSON data I am using the Map function in ReactJS to display elements from a JSON array. I have attempted the code below and encountered an error stating "Cannot read property '_currentElement' of null." Can someone pleas ...

The existing text remains unaltered even after additional details are provided

In the application provided below, a text input does not change after the user adds information from a row. Access the application here. Follow these steps: 1: Open the application and click on "Add Question" to append a table row. 2: Within the append ...

Gradient background overlaid with a blended SVG shape

Creating a full gradient background with a clipping mask can be tricky. I used an SVG to achieve the desired shape by cutting part of the background color, but now I'm facing a challenge with blending the colors seamlessly. I tried setting the SVG co ...

Is it possible to use Vuejs v-model for a complete form instead of individual inputs?

Note: This solution is applicable for Vue 2.X I am currently working on a unique Vue.js component that has the ability to generate "custom" forms. This component essentially functions as a standalone form with multiple input fields. Users have the option ...

Issue with Ajax/Json: "An object of type triggers a circular reference error when attempting to retrieve a list."

Recently, I encountered an issue with my server-side method that is triggered through JSON/Ajax. The method itself functions flawlessly and sends back a list as expected. However, I seem to have made an error in my JavaScript code, leading to the following ...

What is the best way to connect data so that when a user clicks on a specific card, it appears on a popup card

When a user clicks on any card containing data retrieved from a backend API GET method, that data should be displayed in a pop-up card. In my situation, I have two components: DisplayNotes.vue and UpdateNotes.vue. Whenever a user clicks on a displayed card ...

The function initFoodModel is missing and causing issues as it tries to read properties of undefined, specifically attempting to read 'findAll'

myWishlist.js const { setupFoodModel } = require("../../model/FoodModel"); const { setupWishlistModel } = require("../../model/myWishlistModel"); const setupMyWishlistModel = async () =\> { try { const sequelizeConnection = awai ...

Can an SVG be referenced from another location within the HTML document?

I am dealing with extensive dynamic lists that are associated with a large number of individual (generated) SVGs, each representing stylized acronyms. I prefer not to store the generated SVGs in separate files as it would result in numerous requests. Desp ...

Grunt is currently not executing any tasks other than the watch command

I'm currently working on a Bootstrap website and utilizing Grunt to automate tasks. However, I seem to be encountering an issue with my gruntfile as it is only running the 'watch' task and not executing any other tasks. Despite no errors sho ...

The sequencing of operations in Node.js streams

I am having an issue with validating an image before saving it to disk. Currently, I am utilizing the GM library. // Express application implementation app.post('/image', function(req, res) { var stream = gm(req) .size({ bufferStr ...

Responsive on Mobile Devices

I'm seeking assistance in brainstorming a creative idea or method to convert the carousel indicators into a menu, or any alternative approach to ensure the entire section is mobile responsive while keeping all the indicators visible within the mobile ...

Tips for effectively incorporating additional directives into a directive as it is being defined

I'm encountering a significant issue with dynamic directives in angularjs. My goal is to include new directives to a directive while defining it through an object: compile: function () { return { pre: function (scope, iElement, iAttrs) { ...

Achieve focus in EditorFor MVC using JavaScript

You have a button that triggers a pop-up window <a data-dialog="AddProduct" href="@Url.Action("AddProduct", "Outputs")" id="addproduct" class="pop-up-window btn btn-success">Add Product <span class="glyphicon glyphicon-plus-sign" aria-hidden= ...

Should we focus on constructing a category tree for the server or the client side?

For my web application, I have a category tree that is stored in a MySQL database. The app retrieves the data through AJAX calls. I am debating whether to construct the tree on the server side or the client side. Should the server return the constructed ...

I find myself facing a roadblock in navigating Servlets and HTML

I'm currently immersed in a project aimed at launching an innovative online food ordering platform. To bring this vision to life, I've harnessed the power of HTML, CSS, and JavaScript for frontend development, Java (Servlets) for backend function ...

Leverage OnClientClick Event in Asp.net UserControl

Looking for guidance on creating a custom clientside (OnClientClick) event that can be easily subscribed to in the markup of an asp.net page, similar to a standard asp.net control. Are there any tutorials or examples available that demonstrate how to achie ...

CodeIgniter's ajax integration with JSON encoding is failing to function properly

I'm in need of some assistance. The issue I'm facing is that the code seems to be unresponsive, and I can't seem to pinpoint the problem. Below is the code snippet from my View: <div id="ysfhkm_slc_country"> <select name="ysfh ...

What is the best way to optimize CSS formatting for proper loading?

While using Chrome DevTools, I identified the specific section of CSS that requires modification. My goal is to change the color element within this section. The code snippet below was discovered through the "Inspect" feature of Chrome DevTools #header-p ...

The collapsed Navbar button is noticeably wider than expected

My Bootstrap 4 Navbar has a "Logout" button on the left side that appears too wide when the navbar is collapsed. How can I adjust the size of the "Logout" button when the navbar is collapsed? <!doctype html> <html lang="de"> <head> ...