Angular routes cause a glitch in the Bootstrap navbar, causing it to shift to the left on certain active

Apologies for the simple question, I am new to web design and couldn't find a solution even after extensive googling and searching.

The issue I am facing is that when clicking on "EX5" or "EX6" in my navbar, it shifts to the left side of the screen instead of staying at the top.

Here is a snippet of my code:

Navbar:


    <!DOCTYPE html>
    <html ng-app='sampleApp'>
    
    <head>
        <link data-require="bootstrap-css" data-semver="3.3.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" />
        <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6a7a8a1b3aaa7b4e8acb586f7e8f2e8be">[email protected]</a>" src="https://code.angularjs.org/1.4.9/angular.js" data-semver="1.4.9"></script>
        <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dbbab5bcaeb7baa9f5b1a89beaf5eff5a3">[email protected]</a>" src="https://code.angularjs.org/1.4.9/angular-route.js" data-semver="1.4.9"></script>
        <script src="../js/script.js"></script>
        <script src="../js/headerController.js"></script>
    </head>
    
    <body>
    
      <header>
        <nav class="navbar navbar-default" ng-controller="HeaderController">
          <div class="container-fluid">
            <div class="navbar-header">
              <a class="navbar-brand" href="#">JS</a>
            </div>
            <ul class="nav navbar-nav">
              <li ng-class="{ active: isActive('/')}"><a href="#/ex1">EX1</a></li>
              <li ng-class="{ active: isActive('/ex2')}"><a href="#/ex2">EX2</a></li>
              <li ng-class="{ active: isActive('/ex3')}"><a href="#/ex3">EX3</a></li>
              <li ng-class="{ active: isActive('/ex4')}"><a href="#/ex4">EX4</a></li>
              <li ng-class="{ active: isActive('/ex5')}"><a href="#/ex5">EX5</a></li>
              <li ng-class="{ active: isActive('/ex6')}"><a href="#/ex6">EX6</a></li>
               ... <!-- Other list items -->
            </ul>
          </div>
        </nav>
      </header>
      <ng-view></ng-view>
    </body>
    </html>

Exercise 6 Code:


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="../styles/stylesheet.css"> 
        <title>Exercise 6</title>
        <script src="../js/script.js"></script>
    </head>
    <body>
        <div>
            <h2>Add an image, upon clicking, change the image</h2>
            <hr>
            <img onclick="changeImg()" id="sourceImg" src="../styles/images/diluc.jpg" alt="diluc">
        </div>
        
        
    </body>
    </html>

JavaScript Function:

// JavaScript function to change image
var currentImage = "../styles/images/diluc.jpg"

function changeImg(){
  if(currentImage == "../styles/images/diluc.jpg"){
  document.getElementById("sourceImg").src="../styles/images/venti.jpg";
  currentImage = "../styles/images/venti.jpg"
}else{
  document.getElementById("sourceImg").src = "../styles/images/diluc.jpg"
  currentImage = "../styles/images/diluc.jpg"
}
}

/////Navigation Bar
(function () {

  var app = angular.module('sampleApp',['ngRoute']);
  
  app.config(function ($routeProvider){
      $routeProvider
          .when('/',{
              templateUrl:'../exercises/ex1.html'
          })
          .when('/ex2',{
              templateUrl:'../exercises/ex2.html'
          })
           ... <!-- Other route configurations -->
          .otherwise({ redirectTo:'/'});
  });
})();

Header Controller:

(function () { 
 
    var headerController = function ($scope, $location) 
      { 
          $scope.isActive = function (viewLocation) { 
              return viewLocation === $location.path();
          };
      };
      
      angular.module('sampleApp').controller('HeaderController',headerController);
  }()); 

CSS Styling:

#sourceImg{
    width: 500px;
}

I would greatly appreciate your assistance as I am struggling to resolve this issue on my own. Thank you!

Answer №1

Resolved! The problem was found in my CSS script, it seems there were some random characters causing the issue.

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

The image is not appearing on the webpage even though the online URLs are functioning correctly

I am currently facing an issue with my Django portfolio website where I cannot get my photo to display even though the path is correct. However, online images are displaying properly on the site. <html lang="en"><head><link href="https: ...

When clicking on the register button in Node.js, no activity is initiated

Once upon a time, there was a humble express.js app that needed to establish a connection with a mysql database and retrieve user information for registration within the said database. Despite successfully connecting to the database, nothing would happen w ...

Guide for verifying the minimum and maximum values when selecting a particular product from a dropdown menu

My goal is to implement validation for the width textbox when a user selects a specific product from the dropdown menu. The validation should only allow the user to enter a value between 10 and 200. I have successfully retrieved the selected value, but I ...

Is it possible to enclose an image with two <div> tags in a single line?

Can anyone help me with this layout issue I am facing? I have two <div>s wrapping an image in the same row, but for some reason, the right <div> keeps dropping below. I've attempted using float, display:inline-block, and tweaking the styl ...

Error: Unable to access the 'currentStyle' property of null in ChartJS

I am currently utilizing ChartJS to create charts and the system allows for data searching within a specified date range. When searching for a new range, the chart loads correctly. However, when I focus on the chart again, it displays old values. To resol ...

Request a HTML variable and send it to JavaScript

My latest project involves a Binary to Decimal Calculator that is now fully functional, but I am looking to integrate an HTML input into it. <html> <input placeholder="00000000" name="htmlinput"></input> <input id="clickMe" type="butt ...

Creating custom ExpectedConditions with Protractor for detecting attribute changes

I've been working on creating a custom ExpectedConditions method that can wait for an element attribute to change. Here is the approach I came up with: const CustomExpectedCondition = function() { /** * Check if element's attribute matches ...

Using JavaScript to create temporary drawings on a webpage that automatically erase themselves

I am curious about how to achieve a scribble effect that self-erases, similar to what is seen on this website: Example: Thank you! I have come across some similar scripts, but I am struggling to understand how to make the scribble disappear after a few ...

Locate MongoDB documentation pertaining to arrays of objects with two specific fields

For instance, consider a Mongo db collection: [ { "user_id": 1, "lead_id": 901, ... ... }, { "user_id": 2, "lead_id": 902, ... ... }, { "user_id": 2, & ...

Ways to incorporate additional fields into your html/php form

Is there a way to increase the number of fields in my basic form? I want to include fields like username, email, subject, and more. Just looking to add additional fields to the form. <!DOCTYPE html> <html> <head> <title>Storing Fo ...

Transform React.js data from MySql into a variable

Hello there! I encountered an issue while working on coding my web app. **I am looking to execute this class only if the "swishes" value retrieved from a table in my MySQL database is greater than 0.** var thepos = 1; export default class W ...

Can Masonry.js content be perfectly centered?

I am currently experimenting with creating a layout consisting of one to four variable columns per page using the Masonry plugin. I have been impressed with how it functions so far. However, there is an aggravating gap that persists despite my best effort ...

Using Javascript/HTML to enable file uploads in Rails

I'm currently facing an issue with uploading and parsing a file in Rails, as well as displaying the file content in a sortable table. I followed a tutorial on to get started. This is what my index.html.erb View file looks like: <%= form_tag impo ...

Create HTML content dynamically with JavaScript and then utilize AngularJS to interpret and render it

I am creating an HTML table that looks like this: <table id="#webappname"> <tr ng-repeat="data in d"> <td>1 {{data}}</td> <td>2 hey !</td> </tr> </table> To create this, I am using a ...

How can I execute JavaScript within a for loop in the server-side code?

protected void Button1_Click(object sender, EventArgs e) { for (int i = 0; i < 100; i++) { Page.ClientScript.RegisterClientScriptBlock(GetType(), "myScript", "<script>alert('hello world');</script>"); } } Is th ...

Add option button

Is there a way to dynamically add radio buttons using jQuery or JavaScript and save the data into a database? I have successfully appended input types such as text, textarea, checkbox, and select with options. Here is my code: <!DOCTYPE html> < ...

Upgrading to React Router v6: Implementing Loader Functions with Context API

Having issues implementing loaders in React-Router V6 while making a request for a page through a function located in the context file. Unfortunately, I can't access the context from main.js where the router is defined. Main.js import ReactDOM from & ...

The functionality of Vue is acting up with the HTML, unexpectedly refreshing when a button is clicked

I am currently experiencing an issue with my Vue application. When I click the button, it clears the input field (which it shouldn't) and doesn't perform any other actions. The variables "codigo" and "payload" do not display anything on the scree ...

Changing the $scope controller variables based on the URL

My web app consists of a simple table with formatted JSON data. By clicking on a column, users can filter that column in ascending order. I'm looking to modify the URL when this action occurs, like so: www.website.com/column/asc, This way, users ca ...

The process of displaying custom number buttons on the correct input field in react.js

I am facing a challenge in implementing this feature. I have created custom number buttons from 0-9 that users can click on instead of using the keyboard. The issue arises when there are multiple dynamically generated input fields based on JSON Data. For e ...