Place my image in the center of the ul list item within a div

I am having trouble centering an image in my footer. I have tried various solutions but none seem to work. Can someone please take a look at my code and help me out?

HTML

<div class="center">
    <ul>
        <li><a href="#" target="_blank" class="centering_"></a></li>
    </ul>
</div>  

CSS:

.center 
{
    width: 84px;    
    margin: 0 auto;
}
.center ul 
{
    width: 209px;
    line-height: normal;  
}
.center ul li 
{
    float: left;
    margin-right: 11px;
}
.center ul li.last 
{
    margin-right: 0px;
}
.center ul li a
{   
    display: block;
    height: 33px;
    width: 33px;
}

.centering_ {background: transparent url('../images/hello.png') no-repeat;}

EDIT: Here is a example in jsFiddle: http://jsfiddle.net/XJbaM/

I have two icons in my footer and I am looking to remove the right one and center the left one. The text above the icons is already centered.

SOLVED

Answer №1

To implement a wrapper div, follow these steps:

<div>
  <ul>
      <li>
          <div class="wrapper">
              <a href="img"></a>
          </div>
      </li>
  </ul>

Include the following CSS for the wrapper:

.wrapper {
       margin:0 auto;
       width: /* specify the size of your image in PX EM % etc */;
       text-align:center;
}

I have tested this code in my browser and it works perfectly. Here is the complete code snippet that I used, combining elements from both your original code and mine:

    <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
.center 
{
    width: 784px;    
    margin: 0 auto;
    border: 1px solid #000;
}
.center ul 
{
    width: 709px;
    line-height: normal;  

}
.center ul li 
{
    float: left;
    margin-right: 11px;
    border: 1px solid #000;
    width:500px;

}
.wrapper {
    margin:0 auto;
    width:500px;
    text-align:center;
}
.center ul li.last 
{
    margin-right: 0px;
}
.center ul li a
{   
    display:inline-block;
    height: 33px;
    width:100px;
}
.clear {
    clear:left;
}

.centering_ {background-image:url(img/activenav.png);
background-repeat:no-repeat;}
</style>
</head>

<body>
<div class="center">
                <ul>
                    <li><div class="wrapper"><a href="#" target="_blank" class="centering_"></a></div></li>

                </ul>
            <div class="clear">ss</div>
            </div>  
</body>
</html>

The implementation is successful! Enjoy your newfound design enhancement.

Answer №2

To center the div, wrap it with the tags <CENTER> and </CENTER>.

<CENTER>
<div class="center">
                <ul>
                    <li><a href="#" target="_blank" class="centering_"></a></li>

                </ul>
            </div>  
</CENTER>

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

Utilizing JavaScript to retrieve input names from arrays

This is the HTML form that I am currently working with: <form action="#" method="post"> <table> <tr> <td><label>Product:<label> <input type="text" /></td> <td><label>Price:<label> ...

Troubleshooting: Navbar dropdown menu in AngularJS gets hidden within UI layout

After spending some time trying to understand why the NavBar drop-down is getting overlapped inside the ui-layout, I realize that I must be overlooking some basic steps. This issue seems so simple, yet it is eluding me. To see the details of the problem, ...

Utilize AJAX in JavaScript file

I am encountering an issue with the following code: function inicioConsultar(){ $(function(){ $('#serviciosU').change(function(){ if ($('#serviciosU').val()!= "-1") { $.ajax({ url: "@Url. ...

Make sure the div is always positioned above everything, including any built-in pop-up windows

When working with two forms, one for user input and the other as a pop-up window to display results, users sometimes close the pop-up window prematurely if they think there is a network issue causing a delay in data execution. To prevent this, I am consi ...

I'm using Selenium XPATH or CSS to identify and select a checkbox within an HTML table based on the specified text. As a result, I have successfully

I am trying to select a checkbox from an HTML table with multiple columns. Specifically, I want to choose the checkbox that corresponds to the "CLEAN_AUDIT" option for the Name column. However, my current XPATH is selecting 4 checkboxes labeled CLEAN_AUDIT ...

implement a night mode with a single click

I attempted to implement a dark mode using jQuery, but it is not working as expected. I am seeking assistance. I would like to enable the dark mode when clicking on the #btntheme ID, but for some reason, it is not functioning correctly. My goal is to be ...

Dynamically remove the underline tag from a table cell

Within my HTML, I've inserted the code below for a cell: cell.innerHTML = "<u>View All</u>"; In my onclick event for the cell, I have this code (for example, it's based on a condition where I structure the content as shown below, no ...

Filtering data within a specific date range on an HTML table using JavaScript

I am attempting to implement a date filtering feature on my HTML table. Users should be able to input two dates (From and To) and the data in the "Date Column" of the table will be filtered accordingly. The inputs on the page are: <input type="date" i ...

Why does the order of CSS styling impact my design outcome?

Within my CSS file, I have defined the following styles: .myDiv{ float:left; width:100px; height:100px; } .yellow{ background:#faf8c7; } .lightGrey{ background:#f8f8f8; } In my HTML code: <div class="myDiv lightGrey yellow">& ...

Reduce the size of your CSS files using Gulp through the .pipe method

Is it feasible to incorporate a plugin like clean-css to minify CSS every time a page is refreshed or saved? How can I chain it through pipes to ensure that the minified file ends up in the dist folder? Thank you for any assistance! Presented below is the ...

Exploring Scroll Functionality for Inner Components Within Mat-tab

I am currently working on a small attendance project that involves using table components within mat-tab elements. However, I am facing an issue where the overflow from the table causes the entire component to scroll, when in fact I only want the table its ...

To ensure that new tabs are opened directly within jQuery UI tabs, the tab should be created within the jQuery UI tabs interface

I have integrated jquery-UI to create a dynamic Tab panel. When I click on the "Add Tab" button, a new tab is created. However, the new tab does not open automatically. It only opens when clicked on. $(function() { var tabTitle = $( ...

In Bootstrap 5, the anchor tag is causing a shift in the background color of surrounding tags upon being clicked

Why does clicking on an anchor tag temporarily change the background of other tags that weren't clicked? What am I doing wrong? https://i.stack.imgur.com/ZKlUT.png Check out the code below: <nav class="navbar navbar-expand-lg navbar-light bg- ...

Challenge yourself with the act of dragging and dropping multiple times using only Javascript

I'm currently working on implementing a drag and drop functionality from one column to another. The goal is to allow multiple copies of an element from the left list to be placed in the right list. Each copy will have a unique ID assigned before being ...

How to ensure the table fits perfectly on the screen using JQueryMobile and Cordova?

I've been working on a JavaScript function that creates a dynamic page and displays data fetched from a database. However, I've encountered an issue where the displayed data overflows past the width of the mobile screen. Is there a way to ensure ...

Having trouble getting event modifiers to work in Vue when added programmatically

Trying to dynamically add events using v-on through passing an object with event names as keys and handlers as values. It appears that this method does not support or recognize event modifiers such as: v-on=“{‘keydown.enter.prevent’: handler}” T ...

When the input field is in debug mode and has a keydown event listener, the character fails to appear as intended

As a newcomer to javascript/html, I have an input with a keydown event listener. Surprisingly, everything seems to work fine when I try it out in the browser. I type a character and see that my javascript is executed, then I type another character and it w ...

Challenges with iFrame Resizing on Internet Explorer

After following a method highlighted in a forum post to set up an iframe on my webpage, I encountered some issues. To display just a section of the page within the iframe, I utilized the zoom/scale feature available in different browsers. To target a spec ...

the functionality of the multiple dropdown in JavaScript only functions once

Hi everyone, I am new to JavaScript and I am seeking assistance with a dropdown issue I am facing. Currently, I am using a JavaScript code for multi-level dropdowns. However, when I use it for multiple dropdowns, the second dropdown follows the sequence of ...

When trying to upload a file with ng-upload in Angular, the error 'TypeError: Cannot read properties of undefined (reading 'memes')' is encountered

Struggling with an issue for quite some time now. Attempting to upload an image using ng-upload in angular, successfully saving the file in the database, but encountering a 'Cannot read properties of undefined' error once the upload queue is comp ...