Align the login form to the right of the navigation bar

Is there a way to center the navigation items and align a quick login form to the right of the navigation bar using just HTML and CSS? I've tried float: right and display: inline-block, but haven't had any success.

Any suggestions or tips on how to achieve this would be greatly appreciated. Thank you!


nav#navBar {
  text-align: center;
  margin-top: -8px;
  margin-left: -8px;
  border-bottom: 2px solid #191919;
}

nav#navBar ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

nav#navBar ul li {
  font-weight: 600;
  font-size: 14px;
  margin-top: 5px;
  display: inline-block;
  font-family: 'Raleway';
  font-variant: small-caps;
}

nav#navBar ul li a, visited {
  color: #191919;
  text-decoration: none;
  padding: 25px;
  display: block;
}

nav#navBar ul li a:hover {
  color: grey;
  margin-bottom: -2px;
  border-bottom: 2px solid grey;
}

nav#navBar ul.loginForm {
  display: inline-block;
  float: right;
}

Answer №1

Here are the modifications to the CSS:

nav#navBar {
    margin-top: -8px;
    margin-left: -8px;
    border-bottom: 2px solid #191919;
    display: table;
    width: 100%;
}

nav#navBar ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
    display: table-cell;
    vertical-align: middle;
}

nav#navBar ul li {
    font-weight: 600;
    font-size: 14px;
    margin-top: 5px;
    display: inline-block;
    font-family: 'Raleway';
    font-variant: small-caps;
}

nav#navBar ul li a, visited {
    color: #191919;
    text-decoration: none;
    padding: 25px;
    display: block;
}

nav#navBar ul li a:hover {
    color: grey;
    margin-bottom: -2px;
    border-bottom: 2px solid grey;
}

nav#navBar ul.loginForm {
    display: table-cell;
    vertical-align: middle;
    text-align: right;
    padding-right: 25px;
}

No changes needed in the HTML code.

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

How come my div containers are intersecting each other exactly at the center with a height of 50% and width of 50%?

I am facing an issue where the four boxes I created are overlapping, despite being set to a height of 50vh and a width of 50vw. How can I resolve this problem and prevent them from overlapping? https://i.sstatic.net/yRXv1.png https://i.sstatic.net/4hra6. ...

Activate javascript when the screen size is adjusted

I'm using a Bootstrap nav-tab to show and hide different tab-panes based on the screen size thanks to Bootstrap breakpoints. The issue I'm encountering is when a user is on a small screen with the #hide-show tab-pane active, and then resizes the ...

Node.js is experiencing difficulties loading the localhost webpage without displaying any error messages

I am having trouble getting my localhost node.js server to load in any browser. There are no errors, just a buffering symbol on the screen. The code works fine in VS Code. Here is what I have: server.js code: const http = require("http"); const ...

The script generated by document.write is failing to function as expected

A completed JQuery script has been created to enable the movement of a 360° object (picture) based on mouse actions. The code is functional: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title> ...

The margin in the DIV is not aligning correctly with the specified requirements

I encountered a puzzling issue with a small problem, and I am certain that I must be making a mistake somewhere. I experimented with two divs styled using different CSS. <div id="main"> <div id="internal"> hello </div> < ...

How can jQuery select certain parts of content using .html()?

I am facing an issue where the getbalance action is displaying the entire HTML of the site instead of just returning the value. How can I ensure that it only shows the result of the POST request, which in this case is 0? The code snippet is provided belo ...

Extract text from an HTML page using Jsoup

Thinking of creating an android app to track stats? How can I extract kills and deaths data from www.oc.tc/MasterEjzz using Jsoup API? I'm new to Jsoup and could use some guidance. Any assistance on this matter would be highly valued. ...

Exploring Javascript parameters with the power of jquery

Is it possible to pass a parameter from PHP into a JavaScript function within HTML? I am currently facing an issue where my code crashes when it reaches a certain condition. This is the code snippet causing the problem: $str="<input type='submit&a ...

Automatically log out user upon closing the browser window or tab

Currently in the process of creating a chat web application, I encountered an issue. It seems that if a user closes the tab or browser without clicking the 'logout' button, the state in the database will still show them as "online". I am using CO ...

What is the best way to ensure that an image in the navbar changes when hovered over?

In my quest to enhance my skills, I am currently trying to figure out how to create a hover effect on an image within the navbar. My objective is to have the div with the ID of "pic-index" react to hovering over the "HOME" link in the navbar and change the ...

Assigning a class to a table row does not produce any changes

When a user clicks on a table, I am attempting to achieve two tasks using pure Javascript: Retrieve the row number (this functionality is working) Change the background color of the row Below is my current code snippet: document.querySelector('#t ...

Error: The function window.intlTelInput is not recognized within the ReactJS framework

I am currently learning ReactJS and encountering an issue when using jQuery with React JS for intlTelInput. I have installed npm jQuery and imported all the necessary code. Additionally, I have included all the required CSS and jQuery links in my index.htm ...

Stylishly implementing Bootstrap for input elements within labels

Incorporating an input or a textarea within a label and presenting it inline in a Bootstrap 3 styled form has been a challenge for me. Though the code snippet provided below is merely a sample, my original implementation is more intricate. I aim to ensure ...

Navigating jQuery Tabs by Linking to a Specific Tab in a Separate File

I am currently using Bootstrap 3 to develop a basic website. On the about.html page, I have set up Tabs with various content. <ul class="nav nav-tabs" id="TabSomos"> <li class="active"><a href="#somos" data-toggle="tab">About Us</a> ...

Troubleshooting AJAX hover functionality issue

Here is the content that loads through AJAX: <div class="grid"> <div class="thumb"> <img alt="AlbumIcon" src="some-image.jpg"> <div style="bottom:-75px;" class="meta"> <p class="title">Title< ...

Tips for utilizing $.get information to update specific elements on a web page

I am currently utilizing jQuery 1.4.2 to smoothly navigate between similar web pages within Firefox 3. Upon clicking a link, a JavaScript script should load the new HTML, filter out the correct elements and replace them on the existing page. It appears th ...

Ways to showcase a numeric value retrieved from an API on my webpage?

Greetings, esteemed guest! You are visitor number <span id=VisitorCounter></span> <script> fetch("https://unique-api-source.com/visits/getvisitorcount", { method: "GET", // mode: "cors", headers: { ...

How to customize the hover and active properties of a checked checkbox in Vue 3 using Tailwind CSS and PUG?

It seems that checkboxes have a level of sophistication that I never anticipated, or perhaps my brain just can't quite grasp the nuances of checkboxes. After spending a significant amount of time researching and experimenting with checkboxes in a Vue ...

The "Overall Quantity" of items will vary as it goes through different numerical values, despite the fact that I employed --

I am currently working on an e-commerce website with a shopping cart feature. The cart displays the number of items added to it, which increases by one when 'Add to Cart' is clicked and decreases by one when 'Remove' is clicked. However ...

Wordpress Bubble Notification - Conceal at Zero / Reveal at One or More

I am a beginner in PHP and CSS. After extensive reading and learning little by little, I successfully implemented notifications in my project using PHP and CSS. It functions properly, displaying the counts (friends, messages, and notifications) and redire ...