The combination of Asp.net and Bootstrap offers a powerful

I am facing an issue with using Bootstrap in my ASP.NET project. The page displays correctly on a desktop, but when I resize the page to mobile phone size, the navigation panel does not stay in dropdown position. Here is my code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"     Inherits="BootTest.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="navbar navbar-inverse navbar-static-top">

<div class="container">
<a href="#" class="navbar-brand">My Site</a>

<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

<div class="collapse navbar-collapse navHeaderCollapse">

<ul class="nav navbar-nav navbar-right">

<li class="active"><a href="#" >Home</a></li>
<li><a href="#">Blog</a></li>
<li class="dropdown">

<a href="#" class="dropdown-toggle" data-toggle="dropdown">Social Media<b  class="caret"></b></a>
<ul class="dropdown-menu">

<li><a href="#" >facebook</a></li>
<li><a href="#">twitter</a></li>
<li><a href="#" >google+</a></li>
<li><a href="#">instagram</a></li>

</ul>
</li>

<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>

</ul>
</div>

</div>

</div>
<div class="container">
<div class="jumbotron text-center">
<h1>Hello World</h1>
</div>
</div>


<div class="navbar navbar-default navbar-fixed-bottom">
<div class="container">
    <p class="navbar-text">This is a test</p>
    <a class="navbar-btn btn-danger btn pull-right">Subscribe on YouTube</a>
</div>
</div>



    <script src="js/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="js/bootstrap.min.js" type="text/javascript"></script>
</div>
</form>
</body>
</html>

Answer №1

Here is the correct way to write it:

<button class="mobile-toggle" **data-trigger="click"** data-collapse=".header-menu">

Answer №2

Make sure that in your code, the data-target attribute corresponds to the id of the main navbar div element which should be '#bs-example-navbar-collapse-1'.

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

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

Tips for transferring the id from the url to a php function seamlessly without causing a page refresh

I have a div that includes a button (Book it). When the button is clicked, I want to append the id of the item I clicked on to the current URL. Then, use that id to display a popup box with the details of the clicked item without refreshing the page, as it ...

Issue with Passing Value in Function Parameter for jQuery Selector

The RowIndex variable in the provided function does not retain its value when utilized in the gridview selector: function selectRow(RowIndex) { $("#<%= gvwShipments.ClientID %> tr:eq(RowIndex)").css('background-color', &apos ...

Solving Addition and Subtraction Errors in Javascript/Jquery

Upon running the script below, it aims to calculate the height of the browser, as well as the heights of both the header and footer, subtracting them from the initial browser height: var a = $(window).height(); alert (a); var b = $('#header').cs ...

The Kendo grid failed to display the total after the AJAX call

I have a kendo grid that initially loads with some data. @(Html.Kendo().Grid<GridModel>() .Name("Grid") .Columns(columns => { columns.Bound(p => p.ID).Hidden(true); ...

Could there be a coding issue stopping <div class="rating"> from aligning more centrally along the horizontal axis on the screen?

Just wondering, could there be something in my code that's preventing <div class="rating"> from moving closer to the center? And is there a way to make it move closer horizontally? (On a side note, CSS layout and positioning still puzz ...

Vue application experiencing issues with applying Sweet Alert CSS styles

I successfully integrated vue-sweetalert2 into my Vue app (version 2.6). The setup in my main.js file looks like this: import VueSweetalert2 from 'vue-sweetalert2'; Vue.use(VueSweetalert2); In one of my components, I have a basic button with a ...

Display a hidden division when a radio button is selected using Javascript and Jquery

Currently, I am in the process of constructing a form that triggers a series of additional questions based on the selected answer. Below is my current working code snippet: $(".appliedWorked").click(function(){ if($(this).val()==="appliedWorkedYes") ...

Utilizing HTTP PUT for transmitting JSON data via Jquery in Rails 3

HTTP PUT may not work across all browsers, so in Rails (specifically Rails 3), you can use POST and pass the _method query parameter instead. However, this method does not seem to be effective when sending JSON data. For example: $.ajax({ url: window ...

Is there a way I can position my privacy alert so that it appears in front of all DIVs, RevSlider,

Have you had a chance to visit my website at ? I recently added a privacy alert in compliance with the new EU Regulation. However, I'm facing an issue where the alert is overlapping with some of my website components such as other DIVs and Revolution ...

Unable to place within div

Utilizing HTML5 to implement the "DnD" function. There is a button that adds divs. I want to be able to drag items into these newly added divs. Currently, I can only drag into existing divs and not the ones added later. How can I resolve this issue ...

The delete function is not functioning properly after clicking "add to cart," but it works perfectly once the page is

I am encountering an issue with my shopping cart page. When I click on the "add to cart" button, the page refreshes before allowing me to delete an item from the cart. However, if I reload the page after adding an item to the cart, the delete function work ...

Troubleshooting Problems with CSS Before Selector and Margins

Currently, I am attempting to utilize the before selector in order to replicate some list item behavior for elements. Due to constraints where I cannot use list items, it is crucial that I find a way to make styles work effectively. If you would like to s ...

Creating resizable SVG elements using HTML or CSS for dynamic width and height

Is there a way to give my SVG element dynamic width and height in order to display the entire SVG image? For example, take a look at this CodePen link. <svg width="250" height="250" viewBox="0 0 250 250"> Alternatively, .svg { width : 250px; ...

What is the best way to designate unique custom login redirects based on user type?

I am facing a challenge that I can't seem to overcome. Part of the issue is my struggle to articulate it effectively with the right terminology. As a newcomer in this field, please forgive me for posing such a clumsy question. Below is an outline of ...

Ensuring that the initial column of a table remains in place while scrolling horizontally

Thank you for taking the time to read this. I am currently working on a table within a div container (div0) where the data is dynamically generated, resulting in a table with unpredictable height and width. The outer div allows for both vertical and horizo ...

Semantic UI (React): Transforming vertical menu into horizontal layout for mobile responsiveness

I have implemented a vertical menu using Semantic UI React. Here is the structure of my menu: <Grid> <Grid.Column mobile={16} tablet={5} computer={5}> <div className='ui secondary pointing menu vertical compact inherit&apos ...

If a span element is present, apply a specific class to the corresponding

I am working with a dynamic list of links retrieved through AJAX. After parsing the links and appending them to a div, I have encountered an issue where some 'a' elements are followed by a 'span' that needs to be considered. Here is th ...

Solving the issue of jQuery setInterval blocking asynchronous ajax requests

Upon submitting a form, the utilsSubmit function is called. This function sets variables and initiates another function to read a file. If the file does not exist, it will display "Connecting to device...". Once the file is found, the content should be dis ...

When a specific option is selected in a `select` element with the `multiple` attribute, activate the change event

Is it possible to trigger a change event on individual options within a standard select element using jQuery or another method? I want the change event to be triggered on the option elements themselves rather than on the select element, as multiple options ...

Using jQuery's setInterval to consistently refresh the value of a data attribute

I am struggling to dynamically update the data-left value of a div with the class name "tw_marquee_scroller" every 1 second. The intended behavior is for the value to increment by 10 each time, starting at 10 and increasing by 10 in subsequent seconds. H ...