Centering an item within a dropdown navigation bar

Hey there, I'm currently facing a challenge with centering an image within my dropdown bar. My goal is to have it float to the right and be centered, but it's not cooperating. Here's the code snippet I'm working with:

 <!DOCTYPE html>

<html>
<head>
    <title>McBride-Taylor Inc.</title>
    <link rel="shortcut icon" href="/Resources/img/favicon.ico"/>

 <style type="text/css">   
body {
    margin:0;
    padding:0;
    background:#000000
}


.content {
    background:#FFFFFF;
    max-width:80%;
    margin-left: auto;
    margin-right: auto;
    margin-top: 1.5em;
    font: 80% arial;
    border-radius: 5px;
}

.menu {
    font: 67.5% "Lucida Sans Unicode", "Bitstream Vera Sans", "Trebuchet Unicode MS", "Lucida Grande", Verdana, Helvetica, sans-serif;
    font-size:14px;
    font-weight:bold;
    background:#FFFFFF;
    height:50px;
    list-style:none;
    margin:0;
    padding:0;

    border-radius: 15px;
}

.menu > li {
    float:left;
    padding:0px 0px 0px 15px;
}

.menu a {
    color:#000000;
    display:block;
    font-weight:normal;
    line-height:50px;
    margin:0px;
    padding:0px 25px;
    text-align:center;
    text-decoration:none;
}

.menu a:hover{
    background:#000000;
    color:#FFFFFF;

    -webkit-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, .3);
    -moz-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, .3);
    box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, .3);
}

.menu li ul {
    display:none;
    height:auto;
    padding:0px;
    margin:0px;
    position:absolute;
    width:200px;
    z-index:200;
    background:#FFFFFF;

    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
}

.menu li:hover ul {
    display:block;      
}

.menu li li {
    display:block;
    float:none;
    width:200px;
}
?
  </style>
</head>

<body>  
<img src="/Resources/img/Header.png" width=100% style={margin:0;padding:0;}/>

<div>
<ul class="menu">
   <li><a href="/index.html" >Home</a></li>
   <li><a href="#" id="current">About</a>
       <ul>
           <li><a href="/About+Us.html">Company Info</a></li>
       </ul>
   </li>
   <li style="float: right;"><a href="https://www.facebook.com/McBrideTaylorInc"><img src="/Resources/img/facebook.png"/></a></li>
</ul>
</div>

<div class="content">
    <h2 style="text-align: center">About McBride-Taylor</h2>
</div>
</body>
</html>

If you want to take a look, I've hosted it here: . You'll notice that the image is aligned to the right but not vertically centered. I even attempted using v-align without success.

Edit: Upon closer inspection, I removed the text-align property as it wasn't making any difference.

Answer №1

Are you referring to the image on Facebook?

To fix it, simply include vertical-align: middle;.

The issue may be that you used v-align instead of vertical-align.

Avoid using inline styles and opt for classes or ids instead:

<li class="facebook">
    <a href="https://www.facebook.com/McBrideTaylorInc">
        <img src="/Resources/img/facebook.png">
    </a>
</li>

Then apply styling to it:

.facebook{
    float: right; text-align: center;
}
.facebook>a>img{
    vertical-align: middle;
}

Answer №2

To center your image, simply add the vertical-align: middle property.

<img src="/Resources/img/facebook.png" style="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

When I log out and hit the back button, the PHP page continues to display without any changes

After logging out of my PHP session and being redirected to the login page, I am facing an issue where pressing the back button shows me the previous page without requiring a login. How can I fix this problem? Thank you in advance. index.php <form sty ...

Using Python with Selenium, automate the process of clicking on each list item within

Hey there! I recently implemented the code below, and it worked perfectly. However, I'm now trying to figure out how to make it click on all the li items within a ul that have an empty class attribute. Any ideas on how to do this using Xpath? Xpath: ...

The ivory pillar on the far right extending over the entire width of the page

Struggling with Bootstrap to create responsive cards, I encountered a white column that's extending off the page and causing an annoying scroll to the right. Can anyone assist me in resolving this issue? If you have any suggestions on how to achieve ...

What is the reason behind Internet Explorer 11 not supporting conditional comments in HTML? Has this feature been dropped?

I'm having an issue trying to show different content on various web browsers. When using Internet Explorer 11 and Google Chrome 39, the message displayed is "Not Internet Explorer" instead of the expected result. Is there a problem with my code? It&ap ...

What is the proper way to utilize the script type "text/x-template" in a multilanguage context?

I'm currently working with ASP NET and VueJS. In my ASP NET, I have a view component that looks like this: <script type="text/x-template" id="form-template"> @if (string.IsNullOrEmpty(Model.LastName)) { <in ...

Tips on creating a blurred background effect when an HTML popup modal is activated

Whenever I click on a button, a popup window appears. What I want is for the background to be blurred when this popup modal opens. <div class="modal" id="myModal"> <div class="modal-dialog modal-lg"> <div class="modal-content"> ...

Tips for calculating the canvas-relative mouse position on a CSS 3D transformed canvas

Recently decided to challenge myself by experimenting with drawing on 3D transformed canvases. After some trial and error, I managed to get it partially working. const m4 = twgl.m4; [...document.querySelectorAll('canvas')].forEach((canvas) =& ...

Implementing a function trigger upon selection in JavaScript

I'm currently studying JavaScript and working on a basic project that involves generating random strings of different lengths. If you're interested, feel free to check out my codepen code [here][1]. My question revolves around the functionality ...

Guide on building a personalized button layout in Bootstrap 4

I have been working on a React component that I want to stick to the bottom of the screen no matter what content is above it. Even if there is minimal content, I want it to remain at the bottom. To achieve this, I added style={{position: 'fixed' ...

What is the method for identifying which individual element is responsible for activating an event listener?

While working on a color picker project in JavaScript for practice, I encountered an issue. I needed the #screen element to display the selected color when clicked. How can I determine which color has been clicked and pass its value to the function so that ...

What is the best way to adjust inline svg to the user viewport size?

After working on integrating my interactive SVG maps into my HTML pages, I encountered a minor issue: when inserting my inline SVG into a standard, non-responsive HTML document, it automatically adjusts itself to fit nicely within the user's viewport. ...

Creating a shadow effect within an element: a step-by-step guide

I've been experimenting with creating an inner shadow effect on an image, but I can only seem to achieve an outer shadow. Just for clarification, .showSlide is a div element. .showSlide { display: block; width:100%; height:350px; } .showSlide img { ...

I am trying to make my CSS divs remain in the exact same position on the background image, even when the browser is resized both horizontally and vertically. How can I achieve this?

I need the red dot divs to remain fixed on a world map, regardless of browser resize. Not sure if I should be adjusting div properties or background. Here's my CSS code, any feedback is appreciated as I'm new to web design: HTML: <!DOCTYPE ...

Techniques for transferring information to Highchart directly from session storage

I am attempting to populate a pie highchart with data from a session storage variable, but I am not seeing any results. Here is the desired code: $(function () { Highcharts.chart('container', { chart: { type: 'pie', ...

CSS deep level selectors

For the following HTML/CSS code, I am trying to target only level 1 "row" elements and not their nested counterparts. However, when using the child selector, it still selects the nested elements. How can I achieve selecting only level 1 "row" elements? ...

When the submit button on the signup form is pressed, two distinct actions are activated to achieve specific outcomes

I am seeking assistance in implementing code that will trigger the following action: Upon clicking the 'Submit' button on a signup form after the subscriber enters their email address and name, the signup page should reload within the same tab wi ...

Troubleshooting issues with adding child elements in JavaScript

Styling with CSS: ul #allposts li{ height: 50px; width: 50px; background-color: yellow; border: 1px solid yellow; } Creating HTML structure: <ul id = "allposts"></ul> Adding JavaScript functionality: var container = documen ...

Is there a way to retrieve the width and height of a parent element within a nested declaration in SASS?

Is there a way for a child element to automatically adopt the dimensions of its parent? How can I retrieve the width and height values of the parent element in order to achieve this effect? Here is an example code snippet: .thumb { width: 120px; ...

Is there a way in PHP to retrieve database values and display them in HTML text boxes when a button is clicked, all without

Is there a way to dynamically fetch values from a database and display them in text boxes without the need to refresh the page? Here is the PHP code snippet I have been working on: <?php include 'Connection.php'; $sql = mysqli_query($conn ...

The text input field is unresponsive and unable to be selected in the mobile layout

I have implemented this <textarea> component within my web application <div class="col-xs-11 lessSpaceBetweenLine"> <textarea class="form-control actionitems" id="actionitems" name="actionitems" rows="2" pl ...