asp.net menu control automatically hides items that exceed the width of the page

I'm currently using an asp.net menu control created from codebehind for a better user experience. However, when the browser is resized or the resolution is lower than intended, items that don't fit get pushed down to a second line. I want to hide these items instead of pushing them to the next line based on resolution. Here's the code snippet:

<asp:Menu ID="navigation" runat="server" Orientation="Horizontal" CssClass="topmenu" MaximumDynamicDisplayLevels="20"  
 IncludeStyleBlock="false">
 <DynamicSelectedStyle />
 <DynamicMenuItemStyle />
 <DynamicHoverStyle  />
 <DynamicMenuStyle   />
 <StaticMenuItemStyle  />
 <StaticSelectedStyle />
 <StaticHoverStyle  />
 </asp:Menu>

CSS styling:

div.topmenu{}
div.topmenu ul
{
  list-style:none; 
  padding:5px 0; 
  margin:0;
  background: #0b2e56;

}
div.topmenu ul li
{
  float:left; 
  padding:10px;
  color: #fff; 
  height:16px; 
  z-index:9999;
  margin:0;

}

div.topmenu ul li a, div.menu ul li a:visited{ color: #fff;  }

div.topmenu ul li a:hover{ color:#fff;  }

div.topmenu ul li a:active{color:#fff;  }

Answer №1

consider enclosing it in another div, such as:

<div id="navWrapper">
    <asp:Menu ID="navigation" runat="server" Orientation="Horizontal" CssClass="topmenu" MaximumDynamicDisplayLevels="20"  
     IncludeStyleBlock="false">
     <DynamicSelectedStyle />
     <DynamicMenuItemStyle />
     <DynamicHoverStyle  />
     <DynamicMenuStyle   />
     <StaticMenuItemStyle  />
     <StaticSelectedStyle />
     <StaticHoverStyle  />
     </asp:Menu>
</div>

then modify the css accordingly:

div.topmenu{}
div.topmenu ul
{
  list-style:none; 
  padding:5px 0; 
  margin:0;
  background: #0b2e56;
  float: left;
  width: 1000px;    
}
div.topmenu ul li
{
  float:left; 
  padding:10px;
  color: #fff; 
  height:16px; 
  z-index:9999;
  margin:0;

}

div.topmenu ul li a, div.menu ul li a:visited{ color: #fff;  }

div.topmenu ul li a:hover{ color:#fff;  }

div.topmenu ul li a:active{color:#fff;  }

#navWrapper{
    width: 100%;
    overflow: hidden;
    float: left;
}

This approach should ensure that the content remains contained even as the outer div shrinks. Although I haven't tested this myself, following this logic should help achieve the desired result.

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

Automatically close one option upon opening another

Displayed below is the HTML code that I have printed with echo: <input id="58" readonly="readonly" class="cell_to_edit" value="Accepted"> <span id="58" class="toggle_status"> <select class="status_change"> <option>Ac ...

Issue with client-side validation not functioning properly within partial view

When rendering a partial view, my ASP validation is not functioning on the client side. However, it does work correctly on the server side by not updating invalid values. My model inherits from a base class, but I don't see any reason why this would ...

Adding a dynamic form to each row in a table: A step-by-step guide

https://i.sstatic.net/HctnU.jpg Hey there! I'm facing a challenge with dynamically generated rows in a form. I want to send only the inputs from the selected row when a checkbox is clicked. Can you help me figure this out? I tried using let rowForm ...

What happens when dynamically loaded static resources are loaded?

Currently, I am dynamically injecting HTML into a page using JQuery AJAX. The injected HTML contains script and link tags for JS and CSS files respectively. The issue I am facing is that my initPage() function runs before the script containing its definiti ...

The PrimeNG confirmation dialog (Overlay) does not come with any default styling (CSS)

I implemented a PrimeNG confirmation dialog based on the example from their official documentation: component.html <p-confirmDialog appendTo="body" #cd> <p-footer> <button type="button" pButton class="btn btn-primary btn-norma ...

Guide on using jQuery Ajax to send form data to another cs file in ASP.Net

How can I create a form to submit data to another CS file in order to update the database. Below is the form and corresponding code. <form id="form1" runat="server" action="./update.aspx" class="col-md-10"> <asp:Table ID="GridView1" class= ...

Tips for resizing a Textbox by dragging in asp.net?

Is there a way to dynamically adjust the size of a Textbox by dragging it in an ASP.NET application during run-time? ...

What could be the reason for the items not appearing on my bootstrap toggler?

I recently started working with Bootstrap version 5 and I'm trying to implement a navbar toggler. However, when I click on the toggler button, no content is displayed. Here is the code I'm using: <nav class="navbar navbar-expand-lg na ...

Custom stylesheet for individual users?

On my website, users can pick a template for their webpage. After selecting a template, I would like them to have the ability to customize certain styles like the font color. Is there a way to achieve this? I was thinking about saving the user's cus ...

Implementing append operations in JavaScript without relying on the id attribute

Is there a way to specify the second div without assigning it an ID or using any attributes, and then perform an append operation inside it? For instance, indicating that the p element should be appended within the second div without relying on an ID or ...

jQuery for Dynamic CSS Class

Is there a way to apply a different style to a link upon page load with jQuery? I would like the link to appear highlighted when the user navigates to a specific page, such as clicking on the About Us menu item. I want to use jQuery to achieve this effect. ...

When the content in the div exceeds its boundaries, it causes it to overlap with

In my design, I have a top menu with a z-index of 999 to ensure nothing covers it. However, I am facing an issue where a scrolling div is appearing on top of the menu bar even though it shouldn't. Any idea why this is happening? Here is the CSS for t ...

Is it possible to obtain the vertex coordinates of an aframe box?

Is there a way to extract the vertex from an object (specifically a box) in AFRAME, or calculate the intersection between a raycaster and an entity's face? Any assistance would be greatly appreciated. Thank you! EDIT: I have included the code snippet ...

Using Javascript to validate passwords and Bootstrap for design enhancements

I've been working on learning Javascript and some basic HTML using bootstrap v5 recently. One of the tasks I'm currently tackling is creating a Sign-in form and implementing validation for the required fields. While following the Bootstrap docu ...

Refresh menu upon initialization

Having an issue with a function that updates the menu. The problem arises when attempting to call this function at the start of the application in the `onCreate()` method, but it results in an exception because the menu hasn't been created yet. Is the ...

It seems that using the SVG <mask> tag is necessary for Firefox to display correctly, but it causes issues with CSS mask in

I need assistance with masking content using an external SVG image. Currently, I'm using the following code: #homepage-banner .desktop-slider.masked { -webkit-mask:url(news-panel-mask.svg) left top no-repeat; /* Chrome/Safari (Webkit) */ mask: ur ...

What's the best choice: Fixed or Variable Column Widths in Tables or Floats?

I'm currently working on a layout for a 3 column, full-width page. I want two columns to have a fixed width, while the third column should adapt to the full width between them, like this: | Fixed Width || Variable Width || Fixed Width ...

Having difficulty executing the read method of the OleDbDataReader class in C# .NET

For my school project, I am developing an intranet using a form application with the .NET framework and C# language. One of the functions is supposed to populate a data grid within the form. However, I have encountered an issue where the code inside the ...

Issues encountered with integrating external jQuery/JavaScript functions with Wordpress child theme template

After creating a custom template in my WordPress child theme, I added a link to the Bootstrap v3.0.3 .js file stored on my site. While the popup modal is functioning properly, the jQuery tabs seem to be having some issues. Although they are being display ...

What is the method for changing the icon color to dark in Twitter Bootstrap?

I am facing an issue where the icon in my menu tab turns white when active, making it difficult to see. Is there a way to change the color of the icon to black? I have found a class icon-white to make it white, but there is no corresponding class to make ...