Tips for aligning an image vertically within a list item

I am having trouble aligning my image vertically in the li tag.

This is what I currently have:

<nav id='tabs-wrapper'>
  <ul id='tabs'>
    <li><a href='index.html'><img id='btn' src='images/home.png'/></a></li><img class='vert'              
         src='images/vert2.png'/>
    <li><a href='#'>Project</a></li><img class='vert' src='images/vert2.png'/>
    <li><a href='test2.html'>Test</a></li><img class='vert' src='images/vert2.png'/>
    <li><a href='#'>contact</a></li><img class='vert' src='images/vert2.png'/>
  </ul>

CSS

nav #tabs{
float: left;
height: 46px;
}

nav #tabs .vert{
    vertical-align: middle;
}

nav #tabs li{
    display: inline-block;
    height: 42px;
    padding-right:15px;
    padding-left:15px;
}

#tabs li:hover{
    border-bottom:1px solid blue;
    line-height:30px;
}

#tabs li a{
   margin: 0 10px;
   line-height: 48px;
   vertical-align: middle;
}

#btn{
line-height: 48px;
vertical-align: middle;
}

Despite my efforts, the first li (which contains an image) refuses to align vertically with the rest of the list items. Can anyone offer some assistance?

Thank you.

Answer №1

When creating an unordered list in HTML, it's important to remember that anything outside of an <li> element is considered invalid (as shown below with ###).

<li><a href='index.html'><img id='btn' src='images/home.png'/></a></li>###<img class='vert'              
         src='images/vert2.png'/>###

If the image is part of the UI, it should be added as a CSS background rather than an inline image.

Here's an example:

#tabs a {
     display:block;
     background:url(images/vert2.png);
     background-repeat:no-repeat;
     background-position:0px 0px;
     padding-left:30px; 
}

Remember to adjust the padding and background-position according to your layout requirements.

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

Avoiding the resizing of table headers when positioned at the top of a window

Having an issue with resizing elements on a webpage. I have dynamically generated a table from JSON data and have a function that sticks the table header to the top of the page when scrolling: var header = $("#dataheader").offset(); $(window).scroll(func ...

Adjusting layout to second row based on screen width using CSS media query

My div contains the following elements: <div> <a class="postLink" href="{{post.authorLink}}" target="_blank">{{post.author}}</a> <span class="">Published: {{ post.published}}</span> <a class="postLink" href="{ ...

Hide the selection box when hovering over the Div

Looking for a quick solution. I want the option drop down to close when another div element is hovered over. First, open the drop down and hover over the red element on the right side. When hovering over the red element, I would like the drop down to clos ...

Using Ajax to retrieve information from a database and bringing it back

I'm currently working on implementing an Ajax request that can retrieve data from the database in the controller and return it. Here's the code I have in the view: $(".btn-submit").click(function(e) { e.preventDefault(); var name = $("in ...

Utilize the display property with grid to effortlessly expand a block to occupy the entire width

I am currently exploring the grid system and I have a specific challenge. I would like the third block to expand to its full width without the need for extra classes. Can this be achieved using only internal CSS? .grid { margin: 36px auto; height: ...

Mobile responsiveness issue with Bootstrap image heights

Creating a website with an image positioned at the top below the navigation bar. Utilizing Bootstrap 4 and CSS for this project. To ensure that the image spans the full width of the screen on larger devices, I employed background-image. For mobile devices, ...

What is the best way to vertically align a pseudo element image using CSS?

After looking for similar questions, none of the answers seem to be working for my specific issue. This is what I'm struggling with: I am attempting to insert and center a decorative bracket image before and after certain content in the following man ...

Use jQuery to add an anchor tag before an image and then close the anchor tag

Here is the code snippet I am working with: <div id="slider"> <img src="images/p1.jpg" /> <img src="images/p2.jpg" /> <img src="images/p3.jpg" /> </div> I am looking to dynamically add <a> tags before ...

Chrome experiencing problems with placeholder text fallback event

My text field has a placeholder text that says "First Name". When the user clicks on the field, the text disappears and allows them to type in their own text. HTML <input class="fname" type="text" placeholder="First Name"/> JS function handlePlac ...

Trying to decide between using a Javascript or HTML5 PDF Editor?

I am in need of a solution that enables users to edit PDF files directly on an ASP.NET web page. This functionality is intended for creating templates and adding blocks/form fields to existing PDFs, complete with rulers and other necessary features. Desp ...

Ensuring Uniform Column Height in Bootstrap 4 - Preventing Buttons from Being Forced to the Bottom of

Using the Bootstrap 4 class 'h-100' to ensure equal height for all three columns, I encountered an issue where the buttons that were initially aligned to the bottom of each div are no longer in correct alignment. How can I maintain button alignme ...

Tips for implementing jQuery on a CSS selector's :before pseudo-element

My dilemma involves creating a div using CSS with an added X at the top-right corner using the before pseudo-class. How can I implement a function to close this div by clicking on the X with the assistance of javascript? https://i.sstatic.net/Z5uSq.png C ...

Utilizing a drop-down selection menu and a designated container to store chosen preferences

My form includes a select dropdown that displays available options (populated from a PHP database). Users can choose options from the list, which are then added to a box below to show all selected items. However, I am facing a challenge with the multiple s ...

use ajax to dynamically append a dropdown menu

Currently working on creating a form that includes a dropdown menu populated with elements from a database. The challenge I'm facing is ensuring that once an element is selected from the dropdown, another one appears dynamically. My goal is to use AJA ...

Issue with Semantic-UI Special PopUp not displaying on screen

I'm currently working on creating a unique pop-up feature using custom HTML, with the intention of adding content to it later on. My console is displaying the following message: Popup: No visible position could be found for the popup. $(document) ...

Using object URL to set the source of an image is not functioning properly within the electron framework

Currently working on an electron application ("electron": "^5.0.9", running on Windows 10 version 1903) and dealing with a Node.js buffer (Uint8Array) ("node": "v10.6.0") that holds data in the format of "[255, 216, 255, 224, 0, 16,...)" with a MIME type o ...

How to place a child <div> within a parent <div> that is fixed on the page

I am currently working on creating a modal window using HTML/CSS. My goal is to have the modal window fixed in position relative to the browser window, with a white background. Inside the modal, there will be an image at the top and a div element at the bo ...

How can you incorporate a horizontal line beneath your text, similar to the one shown in the

https://i.sstatic.net/OzMVr.jpg I have a code snippet that needs a horizontal border similar to the one shown in the image <section class="about"> <div class="container"> <h1 class="text-center"> ...

Is there a way to create a dropdown menu that transforms into a burger icon on smaller screens, while still housing all of my navigation items within it?

I'm currently working on a segment of my header that includes a navbar with 3 links, as well as a dropdown menu listing additional functionalities. Here is the current code I have: <div class="col-md-4 pt-4"> <nav class="navbar ...

Tips on creating an editable table row in Angular to easily update values

I'm currently developing an Angular application which is meant to extract data from an excel sheet and exhibit it in a table upon upload. I have incorporated an edit link beneath one column for the purpose of editing the row data; once you click on ed ...