Align the image in the center of the Navigation List vertically

I'm working on creating a responsive navigation list with a centered image inside. I've almost got it, but the image appears higher up than the rest of the list.

My goal is to achieve this layout, but I'm having trouble figuring it out: https://i.sstatic.net/xWjxh.png Any assistance would be greatly appreciated!

CODE: https://jsfiddle.net/z50zgpLg/

HTML:

<div class="container-fluid">
            <header>
                <ul class="nav">
                    <li>Home</li>
                    <li>Portfolio</li>
                    <li id="logo">
                        <img src="images/sonis.png"/>
                    </li>
                    <li>About</li>
                    <li>Contact</li>
                </ul>
            </header>
        </div>

CSS:

* {
                margin:0px;
                padding:0px;
            }
            .container-fluid {
                border: 1px solid red;
                width: 100%;
            }

            .nav {
                border: 1px solid black;
                width: 60%; 
                margin:0 auto;
                text-align: center;
            }

            .nav li {
                display: inline-block;
                border: 1px solid red;
            }

            #logo {
                height: auto;
                width: 100px;
            }

            #logo img {
                width: 100px;
                height: auto;
            }

Answer №1

To vertically align content, you can utilize the CSS property vertical-align:middle

Cascading Style Sheets Example

 .nav li {
    display: inline-block;
    border: 1px solid red;
    vertical-align: middle;
 }

Check out the DEMO HERE

Answer №2

To align the items vertically, you can add the property vertical-align: middle to the CSS for the li element. By default, inline-block items have a vertical alignment of baseline, so it is necessary to change this in order to center the items vertically.

.nav li {
    display: inline-block;
    border: 1px solid red;
    vertical-align: middle;
}

Answer №3

If you're seeking a solution, I have created a fiddle that mimics what you're looking for. You can view it here: https://jsfiddle.net/41hgusjr/

To achieve the desired effect, I included padding-bottom: 5px; and padding-top: 5px; for both the logo and the image.

Keep in mind that this adjustment will enlarge the navigation bar.

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

Center text in form-control items on Bootstrap 3 grids

Can you provide guidance on achieving proper alignment of inputs and labels across bootstrap grids? I am looking to ensure that the labels are positioned exactly the same as the first column. Please refer to my plunk: http://plnkr.co/edit/jaMAp38Rr1g7BLW ...

The Youtube Subscribe Embed feature is causing my image to lose its corners

When I use the official embed code from Google Developers to embed my YouTube channel, it cuts off the corners of my image and leaves white corners. This doesn't look good on my website with a black background. <script src="https://apis.google ...

Utilizing TypeScript and Redux for programmatic navigation in React Router within a class component

After investing around 3 hours searching for a solution on how to programmatically navigate using React Router in a TypeScript React class component connected to Redux, I was faced with various type errors that seemed impossible to resolve. Despite only f ...

issue with arranging content in a two-column layout with headers

Currently working on my first website and running into some CSS issues. I'm aiming for a two-column + header layout that fills the entire screen space of the website. I have the following specifications in mind: Header takes up 20% of the screen he ...

Select a different inspiring quote every hour

Wouldn't it be great to add a touch of inspiration to my page with a new motivational quote that changes every hour or day? I'm thinking of compiling all the quotes in a document and having javascript randomly select one to display on my website. ...

Adding dynamic text to a <span> tag within a <p> element is causing a disruption in my layout

I'm encountering an issue with a Dialog box that displays a message to the user regarding file deletion. Here's how it looks: +-----------------------------------------------------------------------+ | Delete File? ...

Pressing the reset button on a basic calculator

I am experiencing an issue with my calculator. It works fine initially, but after using the reset button, it stops functioning properly. Currently, I only have the multiplication set up as I debug this problem. I am new to JavaScript and would appreciate a ...

The font-face feature seems to be having issues on the server with the .NET application

I am having issues with @font-face not working when browsing on Safari 5.1+ from the server URL. The font displays perfectly in Safari when I view the HTML file, but when I convert it to an ASPX (.NET) file, the font appearance is not satisfactory at all. ...

What could be the reason for the absence of a second alert appearing?

I have a small application that validates email addresses for the correct elements, but it's not displaying the confirmation message. $(document).ready(function(){ $("#sendButton").click(function(){ var name = $("#name").val(); ...

Sending JSP parameter to another page via a button click

I am currently working on passing a selected value from a combobox in a JSP to another JSP, and here is my approach: <form name="ff" method="post"> <select name='mat' id='soflow'> <% ArrayList<Matie ...

Fix a bug in IE6 by ensuring that an element takes up 100% of the body when contained within

It appears that this issue is specific to IE6, as the code functions correctly in all other browsers. Check out the jsFiddle link with the HTML code: <div style="background:blue; width:600px; margin-left:auto; margin-right:auto;"> BLUE < ...

Issues with sliding effects in jQuery: slideUp() and slideDown()

My experience with jquery is limited, and I'm facing issues with the slideUp() and slideDown() animations. I've been working on a vCard design inspired by Tim Van Damme's site. You can check out my design at this link. When clicking on the ...

python and html tutorial for adding text from bottom to top

Looking for help with rearranging lines in an HTML file? If you want the lines to be displayed in reverse order, here's an example: (1) (2) (3) You need them to appear like this: (3) (2) (1) try: record_cam.strHandler ...

What is the method to deactivate multiple links using jQuery?

Below is the HTML code: <a title="Login" data-href="/MyAccount/Access/Login" data-title="Admin" data-entity="n/a" id="loginLink" class="nav-button dialogLink"><b>Login</b></a> <a title="Register" data-href="/MyAccou ...

Tips for displaying a div briefly before loading the second page

Incorporating a div named ADD, I aim to successfully load a second page within the current one using ajaxload. The challenge lies in displaying a div for 4 seconds before loading the second page. How can this be achieved? Following the wait period, the sec ...

Adjust the focus on the Angular JS input element

I have a student database with an input text element. When the page loads, I want a student to be highlighted with the input text focused. I created a dynamic class that will set the focus if it is true. If I apply it to a static class, it works fine. How ...

Every time I attempt to create a detail page for a table, I am consistently greeted with an error message

Error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/2909kher/entabell/detaljer.php on line 23 <!doctype ...

I am attempting to retrieve the aria-expanded value using JavaScript, however, I keep receiving an "undefined" response

I'm attempting to dynamically change the class of a <span> element based on the value of the attribute aria-expanded. However, I am encountering an issue where it returns "undefined" instead of the expected value of true or false. Below is the ...

"Navigate to a webpage by interacting with a text hyperlink - Harnessing the

The link I'm trying to click isn't being recognized at all. When inspecting with developer tools in Chrome, the link appears in the following structure: <main <div <ifreame #document <html <body ...

Occasional jquery issue causing font to render incorrectly within iframe

Currently facing a bug that needs resolution, the issue has been identified but unsure of the solution. An iFrame is loaded with content via jQuery like this: var content = {{ json_encode($template) }}; $('#preview-iframe').contents().find(&apo ...