Navigational menu that collapses within a three-column design

I have divided my header into three columns - logo, search bar, and nav.

For the navigation section, I referred to this code snippet: https://codepen.io/macsupport/pen/bKFzD as I am new to bootstrap and still learning.

When viewing on desktop size, I want the menu to be expanded horizontally, and only collapse to a menu icon when it reaches tablet size.

However, due to the fact that it is initially placed in a column one-third of the screen width, it seems like it will always be collapsed.

<header class="fixed-top" id="header">
  <div class="container">
    <div class="row">
      <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
        <img src="media/logo.png" alt="Logo" class="logo">
      </div>
      <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
        <form class="form-inline my-2 my-lg-0 search">
          <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
          <button class="btn btn-secondary my-2 my-sm-0 orange" type="submit">
            <img src="media/icons/search.png" alt="Search" class="icon">
          </button>
        </form>
      </div>
      <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
        <nav class="navbar navbar-inverse text-center" role="navigation">
          <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#nav">
              <img src="media/icons/menu.png" alt="Menu" class="icon">
            </button>
          </div>
          <div class="collapse navbar-collapse" id="nav">
            <ul class="nav navbar-nav">
              <li class="nav-item align-middle"><a class="nav-link grey" href="">Home</a></li>
              <li class="nav-item align-middle"><a class="nav-link grey" href="store">Products</a></li>
              <li class="nav-item align-middle"><a class="nav-link grey" href="blog">Blog</a></li>
            </ul>
          </div>
        </nav>
      </div>
    </div>
  </div>
</header>

Edit

Is there a way to make the collapsible section appear underneath the header from the side, similar to the example shown in this image?

https://i.sstatic.net/tguDg.png

Answer №1

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<header class="fixed-top" id="header">
  <div class="container">
    <div class="row">
      <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
        <img src="media/logo.png" alt="Logo" class="logo">
      </div>
      <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5">
        <form class="form-inline my-2 my-lg-0 search">
          <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
          <button class="btn btn-secondary my-2 my-sm-0 orange" type="submit">
<img src="media/icons/search.png" alt="Search" class="icon">
</button>
        </form>
      </div>
      <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5">
        <nav class="navbar navbar-expand-lg navbar-light bg-light">
          <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

          <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto">
              <li class="nav-item active">
                <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
              </li>
              <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
              </li>
              <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                  <a class="dropdown-item" href="#">Action</a>
                  <a class="dropdown-item" href="#">Another action</a>
                  <div class="dropdown-divider"></div>
                  <a class="dropdown-item" href="#">Something else here</a>
                </div>
              </li>
              <li class="nav-item">
                <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
              </li>
            </ul>
          </div>
        </nav>
      </div>
    </div>
  </div>
</header>

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 causing the issue with document.ready() not functioning properly on this specific page?

Recently, I've been working on a straightforward jquery script to highlight the navigation menu items dynamically. $(document).ready(function(){ $('#header .mm a').each(function(){ if( $(this).attr('href') == window.location. ...

What occurs when Click events are triggered on an <object> element?

I have set up a div, and inside that container, I embedded an SVG image using object (which I plan to manipulate later...). <div id="click-me"> some random Text <object data="some.svg" /> </div> Next, I added event listeners for t ...

Production environment experiencing issues with CSS functionality. Combination of Vue.js, Tailwind, and Netlify not functioning as expected

I am completely baffled...this marks my second vue.js project. When I try to push the site live, it's causing me a lot of trouble. The application functions perfectly locally, but after deploying to netlify and building it, the CSS seems to be malfun ...

Issue with z-index causing the image to not display when navigating through an image gallery with previous and next buttons using

$(document).ready(function(){ $(".divs div.panel").each(function(e) { if (e > 2) $(this).hide(); console.log(e); }); $("#next").click(function(){ if ($ ...

The quickest method to modify the anchor element's class depending on the query string

Requirement - I aim to accomplish this task using only pure JavaScript without any additional libraries, although I am open to using one if necessary. I need to assign an extra class to anchor elements that contain a query string of 'xyz=negate' ...

Create a new instance of the TypeScript singleton for each unit test

I have a TypeScript singleton class structured like this: export default class MySingleton { private constructor({ prop1, prop2, ... }: MySingletonConfig) { this.prop1 = prop1 ?? 'defaultProp1'; this.prop2 = prop2; ...

CSS fails to function properly when the structure of the DOM in the HTML file is

.empty-space{ width: 30%; float: left; } .download-information{ width: 70%; float: left; } .download-thumbnail img { height: 30px; width: 30px; float: left; } .download-profile{ float: left; } <div class="download-cont ...

Tips for transferring the output of a JavaScript async function to a Python variable

var = driver.execute_script("setTimeout(function(){ return [1,2,3]; }, 1000);") Utilizing the Selenium method execute_script, I am attempting to extract data from a website using javascript and assign it to a python variable var. The challenge a ...

Interactive Canvas & Slide Show Presentation - Foundation 6

I am facing a unique problem. My current project involves using the Chart.js library to generate charts within certain div .carousel-item elements. The project also utilizes a Bootstrap 4 template with its own set of css and js. The issue arises when I dy ...

Divide the string into a collection of individual elements

Recently, I received a string from the backend that looks like this: var string = "{name: Hello, age: 20}, {name: Nadia, age: 30}". To transform it into an object, I attempted to push it into an empty array using the following code: var array = [ ...

Unable to assign attribute following discovery

Can the attribute of an anchor element that is found using find() be set? I attempted this: $(this).children('a').setAttribute("href","a link"); Although it does locate the anchor element, why am I receiving an error when trying to use setAttr ...

The issue of error messages not appearing under input fields in Bootstrap 4 and Laravel 5.6 has been puzz

In my Laravel 5.6 project, the blade file contains the following code: <form method="POST" action="/review"> @csrf {{ $errors->first('nickname') }} <input type="hidden" nam ...

Can you provide the keycodes for the numpad keys: "/" and "." specifically for the libraries I am utilizing or any other library that does not overlook them?

I've hit a roadblock with my Chrome Extension development. Despite using two different methods to add keyboard functionality, the keys "/" for divide and "." for decimal on the keypad are just not registering. I've attempted to tackle this issue ...

Using an array.map inside a stateless component with React.createElement: the type provided is invalid

There is a component called BasicDetail in my code with the following structure: import React from "react"; import { Grid, Form } from "semantic-ui-react"; const BasicDetail = ({DetailData}) => { return( <div> <Grid.Ro ...

Automate scrolling to the rightmost column in a table

What is the best way to navigate to the last column in a table with horizontal scrolling without directly targeting the last column? For example, instead of using: document.getElementsByClassName('makeStyles-tableCell-251')[document.getElements ...

When PHP displays values from the $_POST array, it appears as "1" instead of the actual element values

Why isn't PHP reading my values correctly? One Color <input type="radio" name="NumberOfColors" id="oneColor" value="oneColor" checked/><br> Two Colors <input type="radio" name="NumberOfColors" id="twoColor" value="twoColor"/><br& ...

jScrollPane malfunctioning with Bootstrap 3's dropdown menu

I'm attempting to add a vertical scrollbar to a Bootstrap dropdown. Below is the HTML code I'm working with: <div class="btn-group"> <button type="button" class="btn btn-default dropdown-toggle btn_drop_down" data-toggle="dropdown"> ...

Can the color of an ion-radio be adjusted when it is not selected?

I am experiencing an issue where I need to change the default color (grey) to a specific color of my choice, such as the primary color. I have attempted the following methods: <ion-col sizeXs="12" sizeMd="6" class="radio-box"> <ion-item line ...

Delve into the world of tackling catastrophic backtracking with regex in Node

Currently, my node.js script includes this regex: const commentPattern = new RegExp( '(\\/\\*([^*]|[\\r\\n]|(\\*+([^*/]|[\\r\\n])))*\\*+/)|(//.*)', 'g&a ...

Executing jQuery form submission prior to validation

I am facing an issue with validating a form that has inputs with the 'required' attributes. It seems like the "e.preventDefault()" function is not functioning as expected. Despite using it, the form still submits and the POST request goes through ...