Tips for positioning a navigation bar in the center for various screen resolutions

After hours of searching, I still can't find a solution to my problem. I'm new to this, and on my main monitor, everything looks centered just fine.

1920x1080: View larger image

But on my 1280x1024 monitor: View smaller image

As you can see, it's uncomfortably off-balance. Here is the code for my website...

/*---Start Navbar---*/

.nav-main {
  display: block;
  list-style: none;
  position: relative;
  width: 100%;
  height: 70px;
  /* Adds shadow to the bottom of the bar */
  -webkit-box-shadow: 0px 0px 8px 0px #000000;
  -moz-box-shadow: 0px 0px 8px 0px #000000;
  box-shadow: 0px 0px 8px 0px #000000;
  /* Adds the transparent background */
  background-color: rgba(1, 1, 1, 0.8);
  color: rgba(1, 1, 1, 0.8);
}
.nav-logo {
  float: left;
  height: 40px;
  padding: 15px 20px;
  line-height: 60px;
  display: inline-block;
  list-style-type: none;
}
ul {
  text-align: center;
  position: relative;
  margin: 0;
  padding: 0;
  float: left;
  left: 30%;
  list-style-type: none;
  display: inline-block;
}
ul li {
  float: inherit;
}
.nav-item {
  display: inline-block;
  list-style-type: none;
  padding: 15px 20px;
  height: 40px;
  width: auto;
  line-height: 50px;
  color: #fff;
  text-decoration: none;
}
li a:hover {
  background-color: #444;
}
/*---End Navbar---*/
<nav class="nav-main">
  <ul>
    <li>
      <a href="http://phalanxgaming.org/" class="nav-logo" target="_blank">
        <img src="http://i.imgur.com/sg5DZao.png?2" alt="logo" style="width:60px;height:60px;">
      </a>
    </li>
    <li>
      <a href="https://docs.google.com/forms/d/1ukgWHC3_xFmkxiCEhb-ZN9dYw2kHWQEyo_inPW7u0mw/viewform?usp=send_form" class="nav-item" target="_blank">CONTACT US</a>
    </li>
    <li>
      <a href="ts3server://tsgb1.vilayer.com:10022/?nickname=" class="nav-item">TEAMSPEAK</a>
    </li>
    <li>
      <a href="https://www.paypal.me/PhalanxGaming" class="nav-item" target="_blank">DONATE</a>
    </li>
    <li>
      <a href="http://steamcommunity.com/groups/P-GC" class="nav-item" target="_blank">STEAM</a>
    </li>
    <li>
      <a href="http://www.twitch.tv/phalanxgamingofficial/" class="nav-item">TWITCH</a>
    </li>
  </ul>
</nav>

I appreciate any support. Sorry for any mistakes in my writing, I am quite tired and can't sleep until I resolve this issue.

Answer №1

If you want to make your list elements display inline, you just need to adjust some CSS styling.

ul li {
display: inline;
}

You can then remove the float and left attributes from your ul styling and ensure that the height of .nav-mains is set to auto.

For reference, you can view an example here.

Answer №2

Have you considered enclosing it within a div and utilizing the width:auto property?

Answer №3

To start, eliminate the following code:

left: 30%;

that is within the

ul {...}

Next, make adjustments to this section:

ul li {
    display: inline-block;
    vertical-align: middle;
}

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

Displaying images with Javascript when they are clicked

How can I make a speech bubble appear when the image of the person is clicked? <div> <p style="float: left;"><img src="person.png" border="1px"></p> </div> <script> function bubblespeech() { document.getEl ...

Preventing Text Chaos in CSS Layouts: Tips and Tricks

I'm facing an issue with the alignment on this page: . When the page is resized, some of the text links are too long and causing a problem with the layout of the stacked images. How can I fix this? Here is the HTML & CSS code for reference: CSS: #b ...

Issues with JavaScript and CSS functionality not functioning correctly as expected

There seems to be an issue with the order of HTML elements in the following code. When I place the div with the class thumb-bar before the full-img div, the JavaScript functions correctly. However, if I switch their positions, the JavaScript functionalitie ...

In mobile view, the grid text should be positioned on top of the input field

Created a basic grid layout with input fields. Everything looks fine on the PC, but on mobile devices, long text causes the input field to be positioned below the text. However, when the text is short like Lor, it appears next to the input field... I want ...

In PHP/HTML, if the URL is domain.co.uk/?debug, then the following action will

Apologies for what may seem like a basic question, but I've been searching for a clear answer with no luck! My goal is simple - when someone goes to , I want to show extra details, like the code version or any other notes I include. Once again, sorr ...

How to use PHP and JavaScript to update a location marker on Google Maps

I'm new to web development and in need of some help, please. I have a code that is supposed to update the marker location with coordinates retrieved from a database. <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AP ...

Error encountered during PHP GET submission

I am currently working on a PHP page where users can select a season and episode from a form, which will then be sent to a page to play the selected episodes. Below is the form: <form action="view" method="get"> <select> <option name="s" ...

Is there a way to include a textarea or text input in a table row and have it expand upon clicking or dragging, without increasing the row height?

I am looking for a way to allow a textarea to expand or grow when clicked or dragged, without affecting the height of the table row it is in. You can see an example of the issue on this CodePen: https://codepen.io/kerastensorflow/pen/PobaRvK?editors=1010 ...

Evolving fashion trends

I'm looking to dynamically change the style of my HTML element based on screen size, similar to this example: <p [ngStyle]="{'color': isMobile() ? 'red' : 'blue'}">Lorem Ipsum</p> The code above triggers a m ...

Creating a new row does not result in the creation of a new span displaying the character count message

Every description field should have its own character counter, with different SpanIDs displayed in respective SpanIds for each new row. How can this be achieved? <div class="row"> <div class="col-s ...

Issues with refreshing the content in form fields

I am encountering issues with reloading fields, especially the datepicker in a form. The website is live at , and when I attempt to search using the search form, it works fine the first time. However, if I press the reset button before searching again, th ...

A fading transparency box on the border

Looking for a box with varying opacity from left to right (See image for reference - the red marked box has decreasing opacity from right to left). Here is my attempt: .waterMark { background-color: #FFFFFF; float: right; opacity: 0.6; position: ...

Storing the selected value from dynamically generated options in Angular using ngFor

I have a collection of items called Fixtures. Each fixture contains a group of items named FixtureParticipants. Here is my process for generating choices: <tr *ngFor="let fixture of fixtures$ | async; let i=index"> <th scope="row& ...

Excessive screen height causes the CSS box layout to overflow

I am looking to create a screen layout similar to the one shown in this image. It should consist of a row with no overflow and include: A left box that contains: A fixed height header (20px), An aspect square box taking up the remaining height. ...

Is there a way to convert a URL into a clickable link and retrieve the YouTube code embedded within

I have retrieved a string from the database using PHP and I want to echo it. Within this string, there is a YouTube link that I would like to make clickable, as well as extract the YouTube code at the end of the link. How can I achieve this? For example: ...

The challenge of styling React components

Starting a new project with React and Redux has presented me with the challenge of deciding on a styling method. As a newcomer to React, I want to choose a method that won't compromise performance, will offer all CSS3 features, and is easy to maintain ...

Trouble Ensues as CSS Div Refuses to Center

I'm in the process of creating a practice website to improve my HTML and CSS skills, but I'm having trouble centering a specific div. I've attempted to use margin: 0 auto, but it doesn't seem to affect the positioning of the div at all. ...

Strange behaviors when using setinterval with classes

Currently working on enhancing a slider functionality, and I have observed that everything is functioning smoothly - function Slider(element) { this.i = 0; this.element = element; var self = this; this.timer = window.setInterval(functi ...

Is it possible for PHP to not provide an image to HTML?

I'm currently facing an issue trying to display an image in HTML using a PHP script. Despite my best efforts, it's not functioning as expected :-( Here is the code snippet from my image.php script: <? $_GET['f'] = 'all_thre ...

Customizing Your JQuery.awesomeCloud.plugin with a Tooltip Functionality using jQuery

Is it possible to integrate a jQuery Tooltip feature when hovering over specific words in a word cloud? I am currently using [jQuery.awesomeCloud.plugin]:https://github.com/indyarmy/jQuery.awesomeCloud.plugin If there is an alternative method to add toolt ...