Bootstrap showcases different collections of hyperlinks depending on the size of the screen

Having encountered a specific issue, I am dealing with a navbar structure inspired by the documentation provided in this source:

<nav class="navbar navbar-default">
  <div class="container-fluid">
  <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
     </button>
     <a class="navbar-brand" href="#">Brand</a>
  </div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  <ul class="nav navbar-nav">
    <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
    <li><a href="#">Link</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu">
        <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>
        <li role="separator" class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
  </ul>
  <form class="navbar-form navbar-left">
    <div class="form-group">
      <input type="text" class="form-control" placeholder="Search">
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
  <ul class="nav navbar-nav navbar-right">
    <li><a href="#">Link</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu">
        <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><!-- /.navbar-collapse -->

In order to tackle this problem effectively, my objective is to display distinct sets of links on mobile devices when the navbar collapses. I have tried the following methods so far: 1. Creating separate navbar-collapse divs with desired contents and assigning the "bs-example-navbar-collapse-1" ID only to the div intended for mobile view (another div for larger screens also categorized as navbar-collapse but lacking this specific ID to avoid collapsing). Although this method functions, the links from the div with "bs-example-navbar-collapse-1" are visible on large screens as well (when they should be exclusive to mobile). 2. Utilizing the hidden-lg-* class has proved effective, however, it simply hides elements with a display: none property rather than providing two distinct sets of links tailored for regular and mobile screens.

I eagerly welcome any insights or assistance regarding this matter.

Answer №1

Utilize the visible-xs class to display the divs on mobile devices.

Employ the hidden-xs class to hide the divs on mobile screens.

Check out this example below for further guidance:

<!DOCTYPE HTML>
<html>
<head>
<title>DDDD</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<style>
</style>
</head> 
... (The rest of the HTML code is unchanged)

Include the following CSS to enhance the footer appearance:

 footer {
  border-top: 1px solid #ccc;
  box-shadow: 1px 1px 3px #000;
  margin-top:45px;
  padding: 30px 0 0;
}
.bottom-menu{margin:0; padding:0;}
.bottom-menu li{list-style:none; margin-bottom:15px; line-height:15px;}
.bottom-menu li a{color:#4a7e07;  font-size:14px; line-height:18px;}
#footer-btm{background:#593896; padding:8px 0;}
.foot-hd {
  padding: 0 15px;
}
#top-fotter .col-sm-3{margin-bottom:10px;}
.foot-hd a {cursor: pointer;    background: red;    padding: 0px 5px;   color: #fff;}

Answer №2

<ul class="dropdown-menu">
    <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 hidden-xs"></li>
    <li class="hidden-xs"><a href="#">Separated link</a></li>
    <li  class="hidden-lg" role="separator" class="divider "></li>
    <li class="hidden-lg"><a href="#">One more separated link</a></li>
  </ul>

There are two different classes for separator - one for mobile devices and another for desktop.

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

Enhance your application with a redo-undo feature using AngularJS to handle extensive amounts of

At this moment, I am dynamically creating a table where multiple rows are added on the fly, just like in Excel. This table could potentially have millions of rows. To implement redo/undo functionality, I've integrated Angular-Chronicle. Everything wo ...

Use .empty() method to remove all contents from the tbody element after creating a table

Currently, I am working on a project where I am creating a drop-down list to assist users in selecting media and ink for their printers. The goal is to then generate a table displaying the selected results. While I have managed to successfully generate the ...

What is the best way to center text vertically within an image?

How can I vertically align a blog entry title on an entry thumbnail image? The image size changes with the window size and the title varies in length for each entry. After finding a website that successfully achieved this effect, I tried replicating it us ...

What is causing jQuery toggleClass to fail in removing a class?

I have successfully implemented a Skills accordion feature, but I am now trying to add a button that toggles all the skill sections at once. However, I am facing issues with jQuery not correctly adding or removing classes on the .accordion-trigger-all elem ...

Accordion navigation - ensuring the initial div remains open in a default state

<html> <head> <script src="jquery.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $(".content").hide(); $('.button').click(function() { ...

What is the best way to incorporate a PDF file into an HTML document using CSS and HTML without using plugins?

I'm having trouble figuring out how to upload a PDF file. I've attempted using input codes and IMG codes, but they haven't worked. I also tried the herf code, but am not sure how to use it with a PDF file. ...

As the height is expanded, the background color gradually infiltrates the body of the page

I am currently working on an angular application that utilizes angular-pdf. The controller and view function perfectly, and the PDF is displayed correctly, except for one issue. The height of the PDF exceeds the min-height of the module, causing it to expa ...

Trouble with AJAX POST request functionality outside of POSTMAN's scope

Attempting to send data via an AJAX request. Check out the code below: console.log(quote) $.ajax({ url: '{{ path('set_products_in_db') }}', type: 'POST', contentType: "application/json", ...

Setting minimum page height for varying screen resolutions

I encountered a small issue. I am trying to design my website so that it fills at least the full vertical resolution of the user. Here is my HTML code: <div id="head"></div> <div id="body"></div> <div id="legs"></div> ...

The URL you are trying to access is restricted, access denied. Error code: 1012

Trying to periodically ping a server using jquery has been quite the challenge. Despite finding a jquery ajax function that seemed to work for many people, I keep encountering exceptions like "Access to restricted URI denied" in Firefox, Errorcode 0 in IE, ...

Tips on navigating the scroller vertically as the user interacts with a selected div by scrolling up and down

On my webpage, I have various div elements displayed. Each div has the options to move it up or down using the buttons labeled "UP" and "Down". When a user selects a div, they can then use these buttons to adjust its position. I am looking for a way to au ...

delivering data from the controller to the view using ajax

I'm facing an issue while trying to send a model from the view to the controller. All attributes get passed successfully except for the FileData, which is a byte array. Even though Ajax sends it to the controller, it shows up as null. How can I succes ...

Rendering a Pug or EJS file using Express.js results in a Jquery error being thrown

I'm facing a problem with ExpressJs rendering and Jquery integration. In my main file app.js, the code looks like this: restapi=require('express')(); const pug = require('pug'); restapi.use(express.static(__dirname+"/public")); r ...

HTML5 sortable lists, ajax posting, and inactive elements are not functioning correctly

I'm currently utilizing a fantastic plugin for jQuery known as HTML5 Sortable. It can be found at . I am attempting to disable certain items using this plugin. My approach involves adding the class="disabled" to the <li> tag and including items ...

The text beside the radio button appears slightly elevated, rather than perfectly aligned next to it

I'm currently working on HTML radio buttons and I have a slight issue with the alignment of the text near them. The radio buttons are placed correctly, but the text appears to be slightly lifted. Can someone please help me align the text properly next ...

I have a desire to use Javascript to control CSS styles

Within the CSS code below, I am seeking to vary the size of a square randomly. This can be achieved using the Math.random() property in Javascript, but I am uncertain how to apply it to define the size in CSS. #square { width: 100px; height: ...

Display specific pages in a modal window upon loading the page

Recently, I developed a basic modal using jQuery. This modal accepts a URL and loads it via the ajax method, then displays the response HTML in a div designed as a modal box. It's pretty straightforward! The only issue is that these pages are actual ...

Error: The property 'length' cannot be read from an undefined parent causing Uncaught TypeError

Hey there, take a look at this cool stuff http://jsfiddle.net/J9Tza/ <form class="validation"> <div> <input type="email" class="form-control" id="inputEmail" name="email" placeholder="Email" pattern=".{3,200}" title="3 to 200 characters" r ...

"Utilizing React's useState feature to dynamically update numerous dropdown components

Here is a React component snippet: const [show, setshow] = useState(false); const handleShow = () => { setshow(!show); }; Accompanied by the following CSS styles: .show { display: block; } .dropdown_content { padding: 3px; display: none; po ...

Enhance your scheduling capabilities with FullCalendar2's customizable minTime and maxTime settings for each

Can each weekday have different minTime and maxTime in fullcalendar (the hours on the left side)? For example: Monday: 08:00 - 18:00 Tuesday: 08:00 - 18:00 Wednesday: 10:00 - 19:00 Thursday: 13:00 - 20:00 ... The default setting in fullcalendar appl ...