The navigation bar is currently arranged in a stacked formation, but it is not lined up as

Just dipping my toes into web development and experimenting with Bootstrap. Here's a snippet of my code:

<!DOCTYPE html>
<html>
<head>
    <title>IMAGE GALLERY</title>
    <link rel="stylesheet" type="text/css" href="bootstrap.css">
    <style type="text/css" media="screen">
        .navcolor{
            background-color: #042638;
        }   
        .textcolor{
            color: white;
        }
        .align{
            margin-left: 80px;
        }
        .one{
            width: 40px;
            height: 40px;
            color:white;
        }
    </style>
</head>
<body>
    <nav class=" navbar navabar-default navcolor ">
        <div class="navbar-header">
              <img class="one align" src="https://www.pngkey.com/png/full/212-2129758_ios-gallery-icon-png.png" >
              <a href="#" class="navbar-brand textcolor ">IMGS</a>
        </div>
        <ul class="nav navbar-nav ">
            <li><a class="textcolor" href="#">About</a></li>
            <li><a class="textcolor" href="#">Contact</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li><a class="textcolor" href="#">Sign Up</a></li>
            <li><a class="textcolor" href="#">Login</a></li>
        </ul>
    </nav>
</body>
</html>

I'm aware that separating the CSS into its file would be ideal, but for now, I wanted to try something quick. It may look simple, but I was hoping for this. Instead, what I got was this. Disregarding the logo, my concern is how 'About' and 'Contact' are overlapping and somehow centered. I attempted 'navbar-left' and 'pull-left', but it still remains centered. Any assistance would be greatly appreciated.

Answer №1

To align About and Contact side by side, you can make use of flexbox:

.navbar-nav {
  display: flex;
}

If you want to move the links from center to left, a good approach would be to place them in a separate <div> and apply flexbox with justify-content:

.links {
  display: flex;
  justify-content: space-between;
}

You can achieve this with the following code snippet:

<!DOCTYPE html>
<html>

<head>
  <title>IMAGE GALLERY</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <style type="text/css" media="screen">
    .navcolor {
      background-color: #042638;
    }
    
    .textcolor {
      color: white;
    }
    
    .one {
      width: 40px;
      height: 40px;
      color: white;
    }
    
    .navbar {
      display: flex;
    }
    
    .navbar-nav {
      display: flex;
    }
    
    .links {
      flex-grow: 1;
      display: flex;
      justify-content: space-between;
    }
  </style>
</head>

<body>
  <nav class=" navbar navabar-default navcolor ">
    <div class="navbar-header">
      <img class="one align" src="https://www.pngkey.com/png/full/212-2129758_ios-gallery-icon-png.png">
      <a href="#" class="navbar-brand textcolor ">IMGS</a>
    </div>
    <div class="links">
      <ul class="nav navbar-nav ">
        <li><a class="textcolor" href="#">About</a></li>
        <li><a class="textcolor" href="#">Contact</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a class="textcolor" href="#">Sign Up</a></li>
        <li><a class="textcolor" href="#">Login</a></li>
      </ul>
    </div>
  </nav>
</body>

</html>

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 showing data from Ajax responses on an HTML page

In my code, there are two JavaScript functions: The function fetch_items is responsible for returning data in the form of stringvalue. On the other hand, the function extract_items($arr) passes values to the fetch_items function. function fetch_items ...

What is the best way to transition all elements down while sliding a header up or down?

Is it possible to bring down the entire page when hovering over a header element using CSS, ensuring that the header overlaps nothing else on the page? If so, how can this be achieved? See an example of the header in action here: Thank you! ...

Ensure that the following div remains positioned beneath the current one

After reading through this question on Stack Overflow, about creating a responsive table with both vertical and horizontal headers, I came across this particular issue, demonstrated in this codepen example: Currently, the second table appears directly bel ...

Validating Dropzone JS upon submission

I'm working on a form that utilizes dropzone.js for file upload. While I'm successfully validating all the input fields, I'm facing an issue with validating the file upload before submission. I want the submission to proceed only if a file i ...

Issue: Please avoid using HTML tag <img>. Instead, utilize the Image component from 'next/image' - Next.js when working with styled components

While working with Next.js, I encountered an issue with the Image component. Unlike a regular HTML tag, the Image component requires a layout and doesn't offer the same level of control. Additionally, I found that it couldn't be used with framer ...

`Cant see the tag background image in IE7`

I've got some anchor tags that have been assigned the class class='user-home'. To achieve a background image effect, I'm using the following CSS code: .user-options .user-home{ background-image:url('../../img/user-home.png&apo ...

Looking for guidance on how to use Python to populate an HTML document

I have a text file containing a conversation structure like this: name and date message name and date message and I already have an HTML/CSS template and a Python script that can read the text. My goal is to extract each name, date, and message from t ...

An error message stating 'instructions.addEventListener is not a function' appears when using PointerLockControls in three.js

I've been trying to implement PointerLockControls into my project using the example from the THREEJS examples page. I copied the code exactly as it is, but I keep getting errors in the console and the program won't run. My project structure is pr ...

Tall Chakra UI component reaching full height

Is there a way to make my App component use the full height of the screen? I attempted setting the body tag height to 100% in my index.html file, but it did not have the desired effect. ...

Is there a way to activate an event listener specifically for clicking on an image?

Presently, my code consists of a div element that holds two images. The first image has a z-index of 1 and appears behind the second image. I am looking to implement an event listener that will be triggered only when the first image is clicked. Interestin ...

Improving JavaScript event management efficiency through handling numerous asynchronous HTTP requests

Summary: In a SPA CMS project, multiple dynamic data sources are causing performance issues due to a large number of asynchronous HTTP calls required to display a table with extensive data. The challenge is to maintain good performance while handling the ...

Creating a visually appealing background image using WordPress and PHP

Currently struggling with adjusting the width of an image that's set as a background in Wordpress. The text is perfectly centered, but the background image remains full size and I want it to match the container size... You can view the image at the t ...

Dynamically assigning column values based on object properties

I am currently utilizing the Ionic Framework along with its grid system that is reminiscent of Bootstrap. However, I believe my query leans more towards AngularJS than specific Ionic components. Here is what I have: <ion-col *ngFor="let col of row ...

Identifying the pressing of the enter key in an input field

Currently, I am developing an innovative IFrame browser that features an omnibox (identified as "address") and a "GO" button (identified as "submit"). One of the key challenges I'm facing is detecting when the user inputs information and hits the Ente ...

Two servers, each with its own designated form, and a singular database

Hello, I'm managing two servers. One of them has a form and MySQL database where I input data. The other server only includes a form where I want the data filled in to be sent securely to the first server's database. What is the best method for i ...

Instructions for incorporating a glyphicon glyphicon-calendar into a bootstrap dropdown using pug

I am a beginner in the world of pug and I'm trying to include the glyphicon glyphicon-calendar in a dropdown menu labeled "All months". .pull-right select.form-control.btn-primary#selectMonth(style="margin-top: -15px;") option(selected="selecte ...

Utilizing Javascript in Spotfire for enhanced functionality

Currently, I have a dropdown menu with two options ("START" & "END"). Depending on the selected value from this dropdown, I want to display a specific DIV element. I attempted to use the code below, but unfortunately, it is not functioning as expected ...

Exclude certain labeled posts from appearing on the homepage of a Blogger website

I am managing a website dedicated to the best WhatsApp status on my blogger blog. I am in search of a way to conceal certain category posts from appearing on the homepage using coding techniques. Despite extensive research, I have been unsuccessful in fi ...

Having trouble with *ngif not functioning properly after initial click in Angular 6

How do I create a Select field in Angular 6 that will hide or display another div based on the selected value? Below is the code snippet: <div class="form-group"> <label for="servicePriviledges">Managed</label> < ...

Issue with demonstrating the Material Angular expansion-panel feature

Exploring the world of Material Angular has been an exciting journey. Recently, I've been experimenting with adding components to my project. Currently, I'm focused on incorporating the expansion-panel component example into a dialog. However, de ...