Aligning images horizontally within individual div containers within a list

Struggling to align images horizontally, they are all stacked on top of each other.

New to this and could use some assistance figuring it out!

Any help would be appreciated!

<div class="social">
     <ul>
       <div class="facebook">
          <li><a href="#"></a></li>
       </div>
       <div class="twitter">
          <li><a href="#"></a></li>
       </div>
       <div class="youtube">
          <li><a href="#"></a></li>
       </div>
       <div class="vimeo">
          <li><a href="#"></a></li> 
       </div> 
    </ul>
</div>

Here is the CSS code:

.social {
    width: 50%;
    margin: 0;
    text-align: center;
    margin-left: auto;
    margin-right: auto;
    margin-top: 30px;
    display: inline-block;
    position: relative;
}
.social ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.social ul li {
    margin: 0;
    padding: 0;
    display: inline;
}
.facebook a:link {
    background-image: url(../img/facebook.png);
    width: 35px;
    height: 35px;
    background-position: left;
    display: block;
    border: none;
    outline: none;
    position: absolute;
}
.facebook a:hover {
    background-position: bottom;
}
.twitter a:link {
    background-image: url(../img/twitter.png);
    width: 35px;
    height: 35px;
    background-position: left;
    display: block;
    border: none;
    outline: none;
    position: absolute;
}
.twitter a:hover {
    background-position: bottom;
}
.youtube a:link {
    background-image: url(../img/youtube.png);
    width: 35px;
    height: 35px;
    background-position: left;
    display: block;
    border: none;
    outline: none;
}
.youtube a:hover {
    background-position: bottom;
}
.vimeo a:link {
    background-image: url(../img/vimeo.png);
    width: 35px;
    height: 35px;
    background-position: left;
    display: block;
    border: none;
    outline: none;
}
.vimeo a:hover {
    background-position: bottom;
}

View the JSFiddle code here.

Answer №1

My recommendation is to eliminate the div elements and assign the class names to the li elements instead, while also removing the absolute positioning. Check out the Fiddle for reference.

UPDATE: Additionally, utilize the inline-block display property for the li items.

Here's the modified HTML structure:

<div class="social">
     <ul>
          <li class="facebook"><a href="#"></a></li>
          <li class="twitter"><a href="#"></a></li>
          <li class="youtube"><a href="#"></a></li>
          <li class="vimeo"><a href="#"></a></li> 

    </ul>
</div>

And the corresponding CSS styles:

.social {
    width: 50%;
    margin: 0 auto 30px;
    text-align: center;
    display: inline-block;
}
.social ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.social ul li {
    margin: 0;
    padding: 0;
    display: inline-block;

}
.facebook a:link {
    background-image: url(http://www.cruisedeals.com/images_shared/top-deal-star-35px.png);
    width: 35px;
    height: 35px;
    background-position: left;
    display: block;
    border: none;
    outline: none;
}
.facebook a:hover {
    background-position: bottom;
}
.twitter a:link {
    background-image: url(http://upload.wikimedia.org/wikipedia/ca/thumb/a/a0/Logo_upc.png/35px-Logo_upc.png);
    width: 35px;
    height: 35px;
    background-position: left;
    display: block;
    border: none;
    outline: none;
}
.twitter a:hover {
    background-position: bottom;
}

.youtube a:link {
    background-image: url(http://data.cyclowiki.org/images/thumb/d/dc/ClericiMariani.png/35px-ClericiMariani.png);
    width: 35px;
    height: 35px;
    background-position: left;
    display: block;
    border: none;
    outline: none;
}
.youtube a:hover {
    background-position: bottom;
}
.vimeo a:link {
    background-image: url(http://mkhx.joyme.com/images/mkhx/thumb/8/88/%E5%9C%B0%E7%8B%B1.png/35px-%E5%9C%B0%E7%8B%B1.png);
    width: 35px;
    height: 35px;
    background-position: left;
    display: block;
    border: none;
    outline: none;
}
.vimeo a:hover {
    background-position: bottom;
}

Answer №2

Check out the fresh HTML & CSS on this JSFIDDLE link

I made some updates by removing a div inside ul, as it wasn't compliant with standards.

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

Regular expression for selecting characters and numbers in jQuery using a selector

Can someone help me figure out how to select all IDs like this: r1 r2 r3 etc. and not the other IDs like helloWorld I attempted using the CSS selector with jQuery but I'm having trouble understanding how. I tried $('#r[0-9]') but it didn& ...

When using equal-width columns in Bootstrap, the columns will be stacked one on top of the other

When I utilize Bootstrap 5, I am encountering an issue where equal width columns are being displayed one underneath the other. To illustrate, here is a simple example directly from the Bootstrap website: <link rel="stylesheet" href="https://cdn.jsd ...

Enabling a JSON file property to be clickable as needed

I am working with a JSON file obtained from an API call, which contains various objects. My goal is to display the message property of each object, some of which may contain hyperlinks within the message. Here is the HTML code I have implemented to make t ...

Refreshing the parent page in Oracle Apex upon closing the child window.When the child window

I have created an interactive report with a form where the interactive report is on page 2 as the parent page and the form page is on page 3 as the child page. In the parent page, I have written JavaScript to open a modal window (form page - page 3) using ...

Unable to access individual checkbox with Selenium in Java

I am looking to select the Store Pickup Available checkbox on the following page: http://www.target.com/c/pants-shorts-baby-toddler-boys-clothing/-/N-59yk1#navigation=true&viewType=medium&sortBy=newest&isleaf=true&navigationPath=59yk1& ...

How come my menu is not showing up in the same format as the code?

I'm struggling to make the menu align with the text logo. Every time I try, the menu ends up below the logo instead of beside it. Can anyone provide some assistance? nav{ width: 1330px; margin: 0px auto; } nav ul li{ text-transform: up ...

VueJS can manipulate an inline template by dynamically changing its content and reinitializing

this particular query shares similarities with the discussions on VueJS re-compiling HTML in an inline-template component as well as How to implement Vue js directive in an appended html element Regrettably, the approach suggested in those threads is no l ...

Issue with IE 8 compatibility and jquery

Here is the setup of my div: <div class="container"> <div id="myid" style="display:hidden;"> <p>some stuff here</p></div> </div> When I run the command $("myid").slideToggle("slow"); on the above html code (where " ...

Angular 17 | Angular Material 17.3.1: Problem encountered with Angular Material form field focus and blur event handling

I attempted to apply (blur) and (focus) effects to my mat-form-field input field, but it seems like they are not working properly on my system. Here is a code snippet that resembles what I am using: html file <form class="example-form"> ...

Complete the execution of the jQuery function

It may seem like a simple idea - to stop executing a function, just use return false, return, or call on a function like undefined. However, in this case, it's not that straightforward. I'm working on a website project that includes a snake game ...

Guide on manipulating the CSS class of an external library component within our custom component in Angular

My component includes an external library component, and I need to toggle one of the classes in the external component based on a condition in my own component. Since I cannot use ngClass for this purpose, I am hesitant to utilize document.querySelector. ...

The issue of Django/Python static files not loading is causing disruption

mysite/settings.py """ Configuration settings for the Django project called mysite. This file was generated by 'django-admin startproject' using Django 1.9.5. For more details about this file, visit https://docs.djangoproject.com/en/1.9/topics ...

Aligning elements vertically within a parent container

I am facing a problem where elements are not aligning vertically in the center of their parent div. CSS: /* Main body structure */ body{ font-size:0.5em; } .main-wrapper { width: 90%; margin: auto; background-color: #efefef; } * { ...

The previous link is still present in the current URL

Having some trouble with my button code here. I'm new to HTML and I have a button that references another HTML file using a parameter. <a class="btn btn-primary" role="button" href="reto_resultado/{{ clave_primaria }}">Check</a> The issu ...

When a table row is selected, set the OnClick attribute of an input to the value of the TD cell in that row based on

I'm really struggling with this. So, here's the issue - I have a table where rows get assigned a class (selected) when clicked on. Now, there's an input inside a form that needs to redirect to another page when clicked, and it also needs t ...

The appearance of the logout button may differ depending on the web browser being used

I have implemented a straightforward logout button using the following code: <li><a href="http://localhost:8666/web1/profile/mainpage/logout.php" onclick="return confirm('Are you sure to logout?');">Log Out</a>&l ...

Out of nowhere, JavaScript/jQuery ceased to function

Everything was running smoothly on my website with jQuery Ui until I changed the color, and suddenly everything stopped working. Any ideas why this happened? I even tried writing the JavaScript within the HTML file and linking it as a separate .js file, bu ...

Switch up the checkbox status using a hyperlink within the checkbox manipulation strategy

My coworker and I collaborated on a website that features a FAQ page. Each question is followed by an "Answer" spoiler button. By clicking the button, the answer is revealed below the current question and above the next one. Clicking the button again hides ...

Removing a outside div element based on a dropdown change in ASP.NET jQuery

this is the structure of my unique div <div class="row-fluid"> <div class="span12"> <div style="overflow: auto; width: 90%;" class="goleft"> <div style="display: inline-block; width: 200px;"> ...

Updating iframe source dynamically using JavaScript results in the entire webpage refreshing

I am a long-time user of stack overflow and have always found solutions to my issues. However, I am now facing a problem that has me completely stuck, prompting me to sign up and post this question. On my index page, I have multiple iframes with dynamic c ...