What is the best way to arrange list items in this manner?

I am facing challenges with aligning elements properly on the navigation bar. I would like the words (home, players, about, contact) to be vertically centered in relation to the heart logo.

Here is how it currently appears:

This is how I want it to look (created using Photoshop):

The current code I am using:

body {
  padding: 0;
  margin: 0;
  font-size: 15px;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
  background-color: whitesmoke;
}

.container {
  width: 80%;
  margin: auto;
}


/* Header */

header {
  background: black;
  color: whitesmoke;
  padding-top: 30px;
  min-height: 50px;
  border-bottom: #fe1d61 4px solid;
}

header a {
  color: whitesmoke;
  text-decoration: none;
  font-size: 16px;
  font-weight: bold;
}

header ul {
  margin: 0;
  padding: 0 0 20px 0;
  list-style-type: none;
  text-align: center;
}

header li {
  display: inline;
  padding: 0 100px 0 100px;
  height: 30px;
}
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">

<body>
  <header>
    <div class="container">
      <nav>
        <ul>
          <li><a href="index.html">HOME</a></li>
          <li><a href="players.html">PLAYERS</a></li>
          <li>
            <a href="index.html"><img src="img/00nation_logo.png" width="60px"></a>
          </li>
          <li><a href="about.html">ABOUT</a></li>
          <li><a href="contact.html">CONTACT</a></li>
        </ul>
      </nav>
    </div>
  </header>
</body>

Apologies if this question has been asked before, but I have searched for a solution and couldn't find one.

Answer №1

Here is a solution for adjusting the styling of your list items:

nav ul li {
    display: inline-block;
}

Answer №2

To center your image among others, utilize the vertical-align property. Give this a shot:

style="vertical-align: middle;"

Answer №3

To achieve the desired result, additional CSS needs to be added like so:

header li{
    display: inline;
    padding: 0 100px 0 100px;
    height: 30px;
    vertical-align: middle;   // this line should be included
    line-height: normal;      // also add this line
}

Make sure to check the Full Screen view for better visibility.

You can see a complete example below:

body{
    padding: 0;
    margin: 0;
    font-size: 15px;
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
    background-color: whitesmoke;
}

.container{
    width: 80%;
    margin: auto;
}

/* Header */
header{
    background: black;
    color: whitesmoke;
    padding-top: 30px;
    min-height: 50px;
    border-bottom: #fe1d61 4px solid;
}

header a{
    color: whitesmoke;
    text-decoration: none;
    font-size: 14px;
    font-weight: bold;
}

header ul{
    margin: 0;
    padding: 0 0 20px 0;
    list-style-type: none;
    text-align: center;
}

header li{
    display: inline;
    padding: 0 100px 0 100px;
    height: 30px;
    vertical-align: middle;
    line-height: normal;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <meta name="description" content="Norwegian-based esports organization with teams in CS:GO, Rocket League, and many other games.">
    <meta name="author" content="@__jmarcelo__">
    <link rel="stylesheet" href="./css/style.css">
    <title>00 Nation DNB | Home</title>
</head>
<body>
    <header>
        <div class="container">
            <nav>
                <ul>
                    <li><a href="index.html">HOME</a></li>
                    <li><a href="players.html">PLAYERS</a></li>
                    <li><a href="index.html"><img src="https://pbs.twimg.com/media/E-YiHwfXsAEAuiZ.jpg" width="60px"></a></li>
                    <li><a href="about.html">ABOUT</a></li>
                    <li><a href="contact.html">CONTACT</a></li>
                </ul>
            </nav>
        </div>
    </header>
</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 on solving the Navigation bar burger problem with HTML and CSS

## I am having trouble making my navigation bar responsive using HTML and CSS as the navigation burger does not appear in mobile view ## To take a look at my code on jsfiddle, click here: [jsfiddle] (https://jsfiddle.net/abhishekpakhare/nxcdso7k/1/ ...

Create a right-to-left (RTL) CSS file within a create-react-app project and dynamically switch between them depending on changes

I am currently working on a multi-language project using create-react-app. My goal is to incorporate a library like "cssJanus" or "rtlcss" to transform the Sass generated CSS file into a separate file. This way, I can utilize the newly created file when sw ...

Issue with iOS Mobile Safari Navigation Bar/Toolbar when changing orientation

Experiencing some unexpected behavior with iOS mobile safari on version 13.3. I have a website that functions as a single page application for the most part. Due to this, I have set its height/width at 100% and adjusted the content accordingly. While ever ...

JavaScript Empty Input Field when Duplicating Node

I am seeking advice on how to clear the textboxes when an HTML form is cleared. The following JS code runs onclick: var counter = 0; function moreField() { counter++; var newFields = document.getElementById('readroot').cloneN ...

Problem with aligning divs in Bootstrap

I am currently facing a challenge when it comes to aligning my div in Bootstrap 3. My goal is to achieve the following: I have experimented with pull and push commands, but it seems like I still need more practice. Code: <div class="container"> ...

Ways to choose an option from a drop-down menu without the select tag using Selenium

I'm looking to perform automated testing with Selenium using Java but I'm facing an issue when trying to select an item from a dropdown list. The HTML structure does not include a select tag for the drop-down menu items (such as Auth ID and Corre ...

Align the timing of the animation with the dataset in ThreeJS

I am faced with the challenge of working with data that includes time in milliseconds and the x, y, z position of an object at each specific time interval. msec |pos_x |pos_y |pos_z ------------------------------ 0 |318 |24 |3 25 |3 ...

When the user saves the changes on the pop-up window, the main window will automatically refresh

I currently have a calendar feature that allows users to create, edit, and delete appointments. When a user clicks on the new appointment button, it opens a window above the calendar interface. Once the user fills out the necessary fields and clicks save, ...

Using html() to load dynamic data can cause the script to malfunction if the content being loaded contains special characters

Utilizing the html() function, I am retrieving dynamic data from the database and appending it to my HTML. Everything functions correctly, except when the dynamic data contains '>' or '<' tags as data. In this scenario, the script ...

Having an issue with jQuery where trying to append a remove button to a list results in the

Looking to create a dynamic list where users can easily add new items by clicking a button. As each item is added, a corresponding remove button should also be displayed. The issue I'm facing is that every time a new item is added, an extra close but ...

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 ...

tips for incorporating margin without sacrificing responsiveness

Having an issue with three cards in a row, they are too close together without any margin. It doesn't look good, so I tried adding margin, but it messes up the responsiveness that Bootstrap provides. So, I decided to add padding only. Any suggestions ...

Issues with Google maps are causing multiple maps to malfunction

After incorporating some jquery code to create multiple maps upon window load, I noticed a peculiar issue with the maps - they all display the same location despite having different latitudes and longitudes set. Upon inspecting the code responsible for cr ...

Imitate the actions of images with {width: 100%; height : auto} properties

I am interested in creating a unique layout that consists of a stripe composed of images with varying widths and heights. These images need to be proportional, scaled at the same height, and collectively have a width equal to the parent element. However, ...

What are some effective ways to align an image to the left and text to the right within a table

I need to display a member with a higher rank, showing the user image along with their username. However, I am struggling to align the image and text properly due to varying username lengths causing them to appear in a zig-zag position. Here is what I hav ...

Interactive Features in Vue Component

In my Vue Component, I have a prop named src that is bound to a :style attribute like this: <template> <section :class="color" class="hero" :style="{ backgroundImage: src && 'url(' + src + ')' }"> <slot> ...

Deliver JavaScript and HTML through an HTTP response using Node.js

My attempts to send both a JavaScript file and an HTML file as responses seem to be failing, as the client is not receiving either. What could be causing the client to not receive the HTML and JavaScript files? I am using Nodejs along with JavaScript and H ...

Having trouble positioning text alongside a checkbox in Bootstrap v3.3.6?

Dealing with the alignment of checkboxes in Bootstrap forms is driving me crazy. It seems to look almost perfect on both Chrome and IE on my desktop, where the text and checkbox are aligned almost perfectly. However, when I view it on Chrome on my tablet ...

Unexpected issue encountered for identifiers beginning with a numerical digit

Is it possible to select an element from a page with an id that begins with a number? $('#3|assets_main|ast_module|start-iso-date') Upon attempting to do so, the following error occurs: Uncaught Error: Syntax error, unrecognized expression: ...

How to truncate lengthy text in a table on mobile screens using Bootstrap 4

I am currently working on a responsive table that needs to display correctly on both desktop and mobile devices. However, I have run into an issue where long text in the table gets truncated on mobile devices, compromising the responsiveness of the design. ...