Is it possible to move the login button to the right side of the screen?

I'm attempting to move the Login menu all the way to the right on the navigation bar. Currently, all the menu items are aligned to the left and I need to align the Login menu to the right. However, I'm unsure of where to begin.

The navigation menu is generated from an array list in nav.php:

<ul>
 <?php 
      foreach ($navItems as $item) { 
          echo "<li><a href=\"$item[slug]\"><h2>$item[title]</h2></a></li>";                         
      }
 ?>

</ul>

Here is the array list in array.php that the navigation menu items are coming from:-

<?php
//Navigation Menu Items

 $navItems =array( 
        array(
            'slug' => "index.php",
            'title' => "Home"
            ),
        array(
            'slug' => "about.php",
            'title' => "About Us"
            ),
        array(
            'slug' => "why.php",
            'title' => "Why Us"
            ),
        array(
            'slug' => "what.php",
            'title' => "What's Included"
            ),
        array(
            'slug' => "faq.php",
            'title' => "FAQs"
            ),
        array(
            'slug' => "contact.php",
            'title' => "Contact Us"
            ),
        array(
            'slug' => "login.php",
            'title' => "Login"
            ),
  );

?>    

In another file called spacer.php, these elements are included:

   <nav>
        <h2 class="hidden">Our navigation</h2>
          <?php include 'includes/nav.php'; ?>

   </nav>

Below is the CSS for the navigation menu:

nav{   
  margin: 0 auto;
  width: 100%;
  font-size: 18px;
  z-index: 300;
  font-weight: bolder;
  font-family: 'Open Sans', sans-serif;
  text-shadow:0px 1px #D6D0C1 ;
}

nav ul
{
    list-style:none;
}

nav ul li
{
    display:block;
    float:left;
    padding:25px 25px;
}

nav ul li a
{
    font-family: 'Open Sans', sans-serif;
    text-transform:uppercase;
    transition: all .25s ease;
}

nav ul li a:hover
{
    color:#A0522D;
}

You can see a live example here.

Answer №1

Aligning it to the right is as simple as adding a float:right property on the last child of the navigation list.

nav ul li:last-child
{
    float:right;
}

You can also assign a class or id to make the selector easier to style.

For additional customization:

<li>
    <a href="login.php">
        <h2><img style="width: 16px;" src="https://cdn2.iconfinder.com/data/icons/bitsies/128/Enter-128.png"> <span>Login</span>
        </h2>
    </a>
</li>

This is just one of many ways to achieve the desired look, such as using the image as a background or positioning it absolutely or relatively to another element.

If you're new to HTML and CSS, I recommend learning more before diving into web design. There are plenty of resources available online to help you get started.

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

Differences in behavior of multiple select with track by in Angular versions above 1.4.x

I recently upgraded my product from Angular 1.2.x to 1.4.x. Since updating to angularjs 1.4.x, I've encountered an issue: What I have: I included code snippets for both angular 1.2.0 and 1.4.8. You can check out the comparison on JSFIDDLE. Explanat ...

Angular 8 form controls becoming unresponsive while the list is being loaded

Hello, I am currently experiencing an issue in Angular. I have a page with a basic Angular form and two independent components that load lists from an API (comments with 500+ records and posts with 500+ records). The Problem: While trying to enter values ...

Using JavaScript to place image data on the canvas in an overlay fashion

I recently wrote the code below to generate a rectangle on a canvas: <!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canv ...

JavaScript causing attribute() variable to malfunction in CSS animation

I am attempting to implement a CSS animation using three files. Below is the HTML file: <html lang="en"> <head> <link rel="stylesheet" type="text/css" class = "tag" href="../css/style.css" ...

Guiding the jQuery Document

I currently have a stylesheet in the head section with the following content: *, body { direction:rtl; } Upon inspection, I found that the dir variable of jQuery is set to ltr: $(function(){ alert(this.dir); }); How can I obtain the specific page di ...

Looking to display or conceal several divs according to the option selected from a dropdown menu?

I've been searching for a solution to my simple dropdown issue, but haven't had any luck in the forums. This is the code for the dropdown: <select id ="category_faq"> <option value="1">item1</option> <option value= ...

Erase every picture contained within the element

<div id="uniqueidhere"> <span> <span><img src="image1link"></img></span> <span><img src="image2link"></img></span> <span><img src="image3link"></img></span> <span>&l ...

Ionic version 4 ion-img eagerly preloads images instead of implementing lazy-loading

I recently created a horizontal scroller using FlexLayoutModule. It allows me to display a horizontally scrollable list where each item consists of an image and text column. Here's the relevant snippet from my scroller.component.html: <div class=" ...

During my JavaScript coding session, I encountered an issue that reads: "Uncaught TypeError: $(...).popover is not a function". This

Encountering an issue while trying to set up popovers, as I am receiving this error: Uncaught TypeError: $(...).popover is not a function. Bootstrap 5 and jQuery links are included in the code, but despite that, the functionality is still not operational. ...

Having trouble with the visibility of the hover background?

I have a goal in mind: This is the outcome I've achieved so far: LINK My aim is to have a white background with a blue border appear at the bottom when hovering over navigation links. Unfortunately, this isn't happening as expected. Can anyone ...

The appearance of an SVG image inside an absolutely positioned div varies between Firefox and Chrome

The web page I am working on can be found at the following link: This webpage consists of text and SVG images, with the hex bolts positioned over specific areas of the text. Achieving this effect requires absolute positioning within a relatively positione ...

As I spun four images along the outer edge of a circular border, one image came to a halt at 90 degrees, revealing its content. Now, I am looking to enlarge that particular

I managed to rotate four images around a circular border and stop one image at every 45-degree angle. However, I am struggling to enlarge the image that stops at 90 degrees on the website while still showing the content of the respective image when it reac ...

Cursor hovers over button, positioned perfectly in the center

I am facing a challenge with implementing a hover function for a set of buttons on the screen. The goal is to display the mouse pointer at the center of the button upon hovering, rather than the actual position of the cursor being displayed. I have tried u ...

What's the best way to prevent extra spacing when typing in a materialUI TextField?

Instructions for the user: Please input your first name without any spaces between characters. I attempted to implement the following code, however, it did not achieve the desired outcome. <TextField required id="name" label="First Name" ...

Interactive JavaScript Slider for Customizing Selection

Recently, I came across a range slider and I am trying to make it more dynamic. The current JavaScript code has hardcoded references to specific HTML elements, and I want to have multiple sliders on my HTML page, each functioning independently. The code sn ...

How can I incorporate the "onClick()" function within an ajax call, while still utilizing the data returned in the success message?

After successfully making an Ajax call, I would like to implement an on-click function while still utilizing the original data retrieved. $.ajax({ URL: ......, type: 'GET', success: function (res) { var Ob ...

Is there a way to extract the text that is displayed when I hover over a specific element?

When I hover over a product on the e-commerce webpage (), the color name is displayed. I was able to determine the new line in the HTML code that appears when hovering, but I'm unsure how to extract the text ('NAVY'). <div class="ui ...

What is the reason for Sublime 3 highlighting all ID selectors in CSS with yellow?

A single image can convey a multitude of meanings: Sublime 3 (build3083) is highlighting the #something selector as a yellow warning, while .classtag appears to be fine. I don't usually work with CSS, so this issue is quite bothersome. How can I r ...

Managing events with classes

I have multiple divs with the same class. When one of these divs is clicked, I want to change the display of the other divs to 'block'. Currently, I am using inline JavaScript for this functionality, but I would like to achieve it without inline ...

What's the best way to create a unique shape for a Bootstrap div?

Can someone assist me in configuring the bootstrap div col-xs-2 to match the layout shown in the images provided? Your help would be greatly appreciated! Thank you in advance. https://i.stack.imgur.com/afd0p.png https://i.stack.imgur.com/0BGum.png ...