Ways to position bootstrap 4 navigation below header on desktop and above on mobile devices

In my bootstrap 4 grid layout, the first row consists of only a heading. The second row includes a vertical nav that I want to keep aligned with the content by placing it in the same row. However, on desktop only, I would like the heading to appear above the content and nav. On mobile, I want the nav to be positioned in the top left corner. Below is how I achieved this by duplicating the heading. Is there a more efficient way to achieve the same result?

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<div class="container">
  <div class="row hidden-sm-down">
    <div class="col">
      <h1 class="text-center">Desktop Header</h1>
    </div>
  </div>
  <div class="row">
    <!--Nav Bar-->
    <div class="col-md-3 col-lg-2 push-md-8">
      <div class="bootstrap-vertical-nav">
        <button class="btn btn-primary hidden-md-up" type="button" data-toggle="collapse" data-target="#collapseElement" aria-expanded="false" aria-controls="collapseElement">
              <span class="fa fa-navicon"></span>
            </button>
        <div class="collapse fill-gutter" id="collapseElement">
          <ul class="nav flex-column">
            <li class="nav-item">
              <a class="nav-link" href="#">Link 1</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!--End Nav Bar-->
    <div class="col-md-8 col-lg-9 pull-md-3">
      <h1 class="text-center hidden-md-up">Mobile header</h1>
      <div class="row" id="page_body">
        <h2>Content Goes Here</h2>
      </div>
    </div>
  </div>
</div>

Answer №1

If you're looking to differentiate between mobile and PC browsers, there is a simple method to do so.

var filter = "win16|win32|win64|mac|macintel";
var deviceType = "";

if (navigator.platform ) {
    console.log(navigator.platform);
    if (filter.indexOf(navigator.platform.toLowerCase()) < 0) {
        deviceType = "MOBILE";
    } else {
        deviceType = "PC";
    }
    console.log(deviceType);
}

After that, you can customize separate CSS codes for each type of device.

Alternatively, if you prefer not to use this method, you can utilize media queries.

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

Exploring Deeply Nested JSON Data using AngularJS

I'm encountering some difficulties while attempting to extract data from Behance.net. There are two specific issues that I am facing in retrieving the necessary information. The first challenge arises when trying to retrieve the project description. ...

Encountered an issue with the property 'push' not being defined

Here's the schema for my mongoose model in JavaScript: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const CartSchema = new Schema({ userID: String, items: [{ itemID: String, quantity: Number }] }); modul ...

I am experiencing issues with my bootstrap dropdown functionality

I am currently working on implementing a dropdown feature that will be triggered by a button within the search bar. The dropdown content is meant to be displayed underneath the search bar, however, I am facing some issues with my code. <div class="co ...

Browse through the chosen row information on a separate page with the help of angularJS

Hey there, I have a requirement to show the details of a selected row in the next page. In the first page, I am only displaying the name and city fields, and the rest will be visible after clicking a button. Here is my HTML page: <!DOCTYPE html> &l ...

Leverage the PhantomJS variable within the page.evaluateJavaScript function

Currently, I am using PhantomJS to capture a screenshot of the dashboard and save it as a PNG file. Everything works perfectly fine until I try to include additional arguments (line, dFrom, dTo) and use them within the page.evaluateJavaScript() function. U ...

What is the most effective way to set up HTTPS for handling all connections in Node.js?

In my project to create a stateless authentication system using Double Submit Cookie in Node.js/ExpressJs, I am exploring ways to ensure all connections are made over HTTPS. My goal is to optimize for handling high traffic while also prioritizing security ...

Align Bootstrap 4 dropdowns with their parent element

Is there a way to match the width of a bootstrap dropdown menu with its parent input group? <div id="ddl_1" class="input-group"> <input type="text" class="form-control "> <div class="input ...

Console displays null as the attribute value

When I check the console, I notice that the data-postid attribute is displaying 'null'. What could be causing this issue? I would like to view the data-id in the console when clicking on the button with the id modal-save. I have reviewed my cod ...

Bringing in JavaScript files from a Bootstrap theme to incorporate them into a Vue3 application

Incorporating Bootstrap 5, a HTML theme with a CSS bundle file, and separate JS bundle files (main JS bundle file and plugin bundle file) containing Bootstrap code base + custom template features into a Vue 3 project is my current objective. I aim to utili ...

Extracting information from this array using JavaScript

After struggling for a day, I finally managed to get some output from PHP instead of just the word "array". What a relief! (check out this link for the solution) Basically, this is the data returned from an XMLHTTP request to PHP, handled through a JS ca ...

Utilizing Lambda to Analyze PDF Documents with AWS Textract

Struggling with implementing Textract in Lambda to analyze PDF documents using JavaScript. Any assistance would be greatly appreciated. Below is the code snippet: const AWS = require("aws-sdk"); AWS.config.update({ region: proces ...

Position the div to the right of a left navigation bar instead of beneath it using Bootstrap 5

After using the code snippet from , I'm struggling to align content to the right of the navigation bar. It seems like a simple issue related to changes in Bootstrap 5 that I can't seem to figure out. <div class="d-flex flex-column vh-100 ...

Unable to get Jtable to work with ajax post requests

I have encountered an issue while using the code example provided on the JTable website for PHP. I am unable to retrieve values from the AJAX POST request. The JavaScript code in my JTableSimple.php file: $(document).ready(function () { //Prepar ...

Position DIVs next to each other

After scouring through countless Stack Overflow threads in search of a solution to my issue, I still can't seem to get it right. Everyone suggests using float: left, float:right, overflow: hidden, display: block, etc., but none of them are working for ...

Tutorial on inserting a picture into muidatatables

Important Note: The image stored in the database is called "profileImage." I am looking to create a dynamic image object similar to other objects. When I input this code: { label: "Image", name: "profileImage" }, it simply displays the image endpoint as ...

Pairing ASP.NET MVC 5 with the latest Bootstrap 4 framework

My goal is to incorporate a carousel into my webpage. However, after following the steps outlined below, the images are displaying in succession rather than within the carousel format. It's worth noting that other elements of Bootstrap 4, such as card ...

Retrieving the chosen value from Material-UI Autocomplete

Check out the sandbox code here: Problem Having an issue: The Autocomplete component is not retrieving values like the rest of my components. Clicking the Retrieve data button only retrieves values for creator, title, description, project, severity, and s ...

JavaScript progress bar with extended duration, inspired by the success-oriented approach

Currently, I am in search of a unique solution or plugin that can replicate the same effect as Kickstarter's crowd fund long term progression bar. It seems like existing solutions only offer short term dynamic progress bars that indicate the percentag ...

Issue with Bootstrap Table Column Width Not Adjusting as Expected

Table columns are not adjusting width properly with the table-responsive class. I want to specify the width of the column containing Well Type to be 200px. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="st ...

Dynamic content within an HTML tree format

Data retrieved from the database is currently in the following format upon query execution [(‘Country-1’, ‘state1’), (‘Country-1’, ‘state2’), (‘Country-1’, ‘state3’), (‘Country-2’, ‘state1’), (‘Country-2’, ‘state2’) ...