"Fixing the TopMenu in ASP.NET: A step-by-step guide

No Fixed

https://i.sstatic.net/84wsi.png

Fixed

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

Layout Issue (_Layout Side)

<div style="text-align:center; max-width:1200px; min-width:1200px; min-height:30px; padding:5px 0; text-align:left; left:26.3%; position:fixed; z-index:1" class="container">
    <a style="color:#e2c75b; font-weight:bold; font-size:20px; text-decoration:none;" asp-area="" asp-page="/Index">
        <img src="~/Images/abc.png" height="30" width="30" style="border: 0; float: left; margin-right: 10px;"/>
        <span>ABC</span>
    </a>
</div>

<main role="main" class="pb-3">
    @RenderBody()
</main>

This might cause overlap.

The readability is not optimal. Apologies for that.

I hope it resembles the image of "No Fixed" when fixed.

Answer №1

It appears that you are in the process of creating a fixed div at the top of your page, but it seems to be overlapping with other HTML elements. When fixing an element to the top, ensure there is enough space for the other elements to display properly. I noticed you are utilizing bootstrap4 as indicated by the pb-3 class you are using. Instead of trying to reinvent the wheel, consider leveraging bootstrap classes to achieve your desired layout.

<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
  <!-- Brand -->
  <a class="navbar-brand" href="#">
      <img src="~/Images/abc.png" height="30" width="30" style="border: 0; float: left; "/>
  </a>

  <!-- Toggler/collapsible Button -->
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
    <span class="navbar-toggler-icon"></span>
  </button>

  <!-- Navbar links -->
  <div class="collapse navbar-collapse" id="collapsibleNavbar">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
    </ul>
  </div>
</nav>

To resolve this issue, adjust the padding of the body or margin of the containing div element where the rest of the content resides.

<main role="main" class="pb-3" style='margin-top: 80px'>
    @RenderBody()
</main>

If you prefer not to use bootstrap and stick to your own code, make sure to set the appropriate margin for the main element you have created.

Answer №2

The solution I found from Jamshaid Kamran was very helpful.

<nav class="navbar navbar-expand-sm bg-white navbar-dark fixed-top" style="background-color:white;width:100%; height:40px;">
    <div style="text-align:left; width:1200px; margin-left:auto; margin-right:auto">
        <a style="color:#e2c75b; font-weight:bold; font-size:18px; text-decoration:none;" asp-area="" asp-page="/Index">
            <img src="~/Images/abc.png" height="24" width="24" style="border: 0; margin-right: 0px;" />
            <span>NcoreSoft</span>
        </a>
    </div>
</nav>

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

Localizing Dates in JavaScript

I'm currently dealing with localization and globalization in an ASP.NET application. As I navigate through this process, I am encountering difficulties in getting the Date() function in JavaScript to function correctly based on the user's locatio ...

Tips for retrieving information from an unstructured scraped webpage

After coming across an interesting post on a baseball stat website, I am eager to conduct some analysis. The specific page I am referring to can be found at The data I am interested in scraping is the information starting from the player's name (acco ...

The autocomplete feature in Codemirror seems to be failing specifically when writing JavaScript code

I am having trouble implementing the autocomplete feature in my JavaScript code editor using Codemirror. Can someone please help me figure out what I'm doing wrong? Here is the snippet of code : var editor = CodeMirror.fromTextArea(myTextarea, { ...

Angular Material Slider is failing to display properly

I am struggling to get the Angular Material Slider to render correctly in my project. Here is the code I have been using: <div class="row formField" ng-cloak> <div class="col-md-2"> <div>送貨日期</div> & ...

Struggling with ThreeJS bufferGeometry position attribute not refreshing after applying translation

Leveraging STLLoader, I successfully loaded an stl file onto a threeJS scene and obtained a BufferGeometry. Following that, I utilized myMesh.position.set(x, y, z) myMesh.rotation.setFromQuaternion(quaternion, 'XYZ'); to manipulate the geome ...

How to extract postback data from dynamically generated controls in MVC without relying on FormCollection

When passing a List to an MVC view, I am generating checkboxes for each object in the list and naming them t.Name. After posting the form, I want to determine which checkboxes were checked without using the FormCollection object. Is there a different meth ...

Is it necessary to call Dispose() after every FindViewById call?

Is it necessary to call Dispose() after using FindViewById in Android Xamarin to prevent memory leaks? For example: void SetTextSomewhereInMyView() { var myTextView = FindViewById<TextView>(Resouce.Id.myTextView); myTextView.Text = "This is my Text ...

Clearing the text field after submitting the content

I am trying to remove the content of a text field after adding an option into a select list. Here is an example of the HTML code: <select size="15" style="width:230px" style="text-align:right" id="theaterSelectControl"> <option>111</opt ...

The inefficiency of invoking Jquery on elements that do not exist for the purpose of caching

What is the impact if JQuery attempts to access elements that do not exist? Will there be any significant CPU overhead other than script loading? Does it matter if this is done for a class or an id? For optimization purposes and to minimize simultaneous c ...

Expanding Images with React-Bootstrap Cards

I need assistance with setting up cards in React-Bootstrap. The Card component is enlarging my images beyond their original sizes. When I attempt to place the image in an img tag outside of the card, it displays at its normal size. Can someone provide guid ...

Submitting the form without utilizing Ajax, but instead sending data directly to a PHP script

I've encountered an issue while posting a form to a PHP file using AJAX. Despite my efforts, the form is bypassing AJAX and posting directly to the PHP file. Here is my form: <form id="editform" name="editform" action="ajaxeditform.php" method= ...

CSS Issue: Hovering Over Link Causes Text to Shift in Internet Explorer

Encountering a problem with CSS and IE, specifically in Internet Explorer 9. When hovering over certain links, the text shifts down which does not occur when using Firefox. You can see an example of this issue at: http://www.debtdispatch.com/list_item_err ...

Reversing the sequence of code in JavaScript - react native

I'm currently working on tracking the number of times a button is pressed within one second. For the most part, it's functioning correctly as it tracks and displays the count. The issue arises when it displays the button press count from the pr ...

Showing content generated by a JavaScript function

Having issues displaying the output of a JavaScript function that outputs text in seconds on my HTML page. The function I am using is: hypeDocument.currentTimeInTimelineNamed(timelineName) I've tried several solutions without success. My latest atte ...

Using AJAX does not automatically trigger the form submission process

It seems like the preventDefault function is working as intended to prevent the form from posting. However, the update() function is not sending the form data to the specified URL. I am perplexed by this issue and unsure of why it is happening. UPDATE: I ...

Having trouble with validating XML against DTD in C#?

I've been dealing with this issue for the past few days. I'm attempting to upload an XML file and load it into an XmlDocument object, but I keep receiving the following error message: For security reasons DTD is prohibited in this XML document. ...

Converting Dates with Ractive.js

Is there a way to transform the Epoch time value retrieved from a JSON endpoint into a readable time string format such as "Tue 19 Jan 11:14:07 SGT 2038" without relying on external libraries like moment.js? var ractive = new Ractive({ el: '#cont ...

Passport is implementing multistrategies for multiple authentications simultaneously

After configuring Passport.js to utilize multiple strategies, I encountered an issue: passport.authenticate(['bearer', 'facebook-token', 'google-token', 'linkedin-token'],function(err, user, info) ... Although it i ...

Enhance autocomplete suggestions by including supplementary information

A unique feature on my website is a field that provides autocomplete options for person names, such as "Obama, Barack" or "Lincoln, Abe." These individuals also come with additional attributes, like "Birthplace" and "Phone number." I want the selected opt ...

Is it feasible to position an iFrame in the bottom right corner of the browser using CSS?

I'm trying to align an iFrame to the bottom right corner of the browser window using CSS. Initially, the following code seems to do the trick. However, if the page containing the iFrame has a horizontal scroll bar, the iFrame does not adjust its vert ...