Aligning an icon font in a CSS circle within a parent element

I'm facing an issue with centering 3 CSS circles containing icon fonts inside their parent element. No matter what I try, I can't seem to get them properly centered and aligned side by side. I initially used float: left to align them, but it ended up causing problems with the hover effect.

If you want to see the problem in action, you can check out this link. Just head to the portfolio section and hover over one of the members.

Here's how it is supposed to look:

And here's how it currently looks:

This is the HTML code snippet:

<ul class="img-list">
  <li>
    <img src="img/team-member-1.jpg" alt="...">
    <span class="text-content">
        <span>
            <div class="social-icon-holder">
                <span class="ion-social-twitter social-icon"></span>
            </div>
            <div class="social-icon-holder">
                <span class="ion-social-facebook social-icon"></span>
            </div>
            <div class="social-icon-holder">
                <span class="ion-social-dribbble social-icon"></span>
            </div>
            Johnathan Adams
            <p>Developer</p>
        </span>
    </span>
  </li>
</ul>

This is the corresponding CSS code:

/* =Team
-------------------------------------------------------------- */
.team {
    padding: 180px 0 180px 0;
}

.team img {
    width: 100%;
    height: 100%;
}

ul.img-list {
    list-style-type: none;
    padding: 0;
}

ul.img-list li {
    display: inline-block;
    position: relative;
    height: 350px;
}

span.text-content {
   // CSS properties go here
}

span.text-content span {
    // CSS properties go here
}

ul.img-list li:hover span.text-content {
    // Hover effect CSS properties go here
}

.team span p {
    // CSS properties go here
}

.social-icon {
    // CSS properties go here
}

.social-icon-holder {
    // CSS properties go here
}

.social-icon-holder:hover {
    // CSS properties go here
}

.social-icon-holder:hover .social-icon {
    // CSS properties go here
}

Answer №1

Enclose the team member's name within a <p> tag to turn it into a block element and position it on a new line.

Next, in the .social-icon-holder{

modify

display:table;

to

display:inline-block;

or

display:inline-table;

Check out this JsFiddle link for reference.

In the JsFiddle provided, I simply used a placeholder background image.

To align the social icons at the center, I applied the following CSS:

.social-icon {
    font-size: 12px;
    color: #fff;
    display: block;
    text-align:center;
    width:30px;
    height:30px;
}

View this updated JsFiddle link for more details.

Answer №2

To achieve the desired circle icon alignment, the style rule display: table in the .social-icon-holder class should be removed and replaced with display: table-cell;.

In addition, for proper icon alignment within the circle, you can adjust the font-size and apply a slight padding to the icons.

The example provided below demonstrates how this adjustment can be applied specifically for the Facebook icon. This can also be implemented for other icons by targeting the .social-icon class.

.ion-social-facebook:before {
content: "\f231";
font-size: 2em; /*Increase icon size*/
padding-left: .4em;
}

Answer №3

Referencing my previous comment: http://jsfiddle.net/h7kJS/. For the complete result, visit: http://jsfiddle.net/h7kJS/2/embedded/result/.

If you want to display .social-icon-holder as an inline-table, you can also use a combination of inline-block and line-height.

To simplify things, position the image absolutely under .text-content. Here is an updated CSS code where .team has been replaced with .img-list:

/* =Team
-------------------------------------------------------------- */
.img-list {/* update */
    padding: 180px 0 180px 0;
}

.img-list img {/* update */
    width: 100%;
    height: 100%;
    position:absolute;/* update */
    z-index:0;/* update */
}

ul.img-list {
    list-style-type: none;
    padding: 0;
}

ul.img-list li {
    display: inline-block;
    position: relative;
    height: 350px;
    width:350px;/* update */
}

span.text-content {
    background: rgba(39,39,39,0.75);
    color: white;
    cursor: pointer;
    display: table;
    left: 0;
    top: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
}

span.text-content span {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
    height:100%;
    width:100%;
}

ul.img-list li:hover span.text-content {
    opacity: 1;
    transition: opacity 500ms;
    position:relative;/* update */
}

.team span p {
    font-family: 'Montserrat', sans-serif;
    text-transform: uppercase;
    font-size: 14px;
    color: #a5a5a5;
}

.social-icon {
    font-size: 12px;
    color: #fff;
    margin: 0 auto;
    display: table-cell;
    vertical-align: middle;
}

.social-icon-holder {
    border: 2px solid #fff;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: inline-table;/* update */
}

.social-icon-holder:hover {
    background-color: #fff;
    cursor: pointer;
}

.social-icon-holder:hover .social-icon {
    color: #272727;
    cursor: pointer;
    transition: color 0.5s ease;
}

Answer №4

Would you like to give this code a try?

.social-icon-holder {
    border: 2px solid #FFFFFF;
    border-radius: 50%;
    height: 30px;
    width: 30px;

   display: block;
   margin: 0 auto;
}

Answer №5

Follow these steps:

<span>
 <div class="social">
   <div class="social-icon-holder">
      <span class="ion-social-twitter social-icon"></span>
   </div>
   <div class="social-icon-holder">
      <span class="ion-social-twitter social-icon"></span>
   </div>
   <div class="social-icon-holder">
      <span class="ion-social-twitter social-icon"></span>
   </div>
 </div>
</span>

--- css styles --

.social div{
  display: inline-block;
}

.social-icon{
  padding: 8px 10px;
}

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

What is causing this issue with the basic HTML and CSS code that is preventing it from displaying correctly

What does the HTML code look like? <html> <head> <title>Homepage</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="container"></div> </body> </html> ...

Accessing HTML elements that are created dynamically in AngularJS

I am facing an issue where I cannot access a function within a newly created DOM element. Despite my best efforts, I can't seem to figure out what is causing this problem. $scope.createCustomHTMLContent = function(img, evtTime, cmname, evt, cust, ser ...

Calculating totals in real-time with JavaScript for a dynamic PHP and HTML form that includes quantity,

I have created a dynamic form with fields and a table that adjusts based on the number of results. Each column in the form represents name, quantity, price, and total price. The PHP and SQL code runs in a loop to populate the list depending on the number ...

Can you assist with transforming the html, css, and js code into a svelte format using style lang="postcss" specifically for tailwind?

I'm attempting to transform this shining button from a codepen I discovered into a svelte component, but for some reason the sparkles don't appear. I'm unsure if it's relevant, but I'm also utilizing Tailwind CSS, so my style tag h ...

What is the best way to access the display property of a DOM element?

<html> <style type="text/css"> a { display: none; } </style> <body> <p id="p"> a paragraph </p> <a href="http://www.google.com" id="a">google</a> &l ...

Animating images on scroll using Bootstrap's utilities

Is it possible to use bootstrap for creating a responsive animation of a bicycle moving from start to end as the user scrolls down the page? Additionally, how can I incorporate a responsive dotted line using bootstrap as well? Are there any codepen exampl ...

What might be the reason for jQuery not functioning in Internet Explorer 11?

Working on developing a slideout menu for my website using jQuery. It functions perfectly in Chrome, but encountering issues in Internet Explorer (IE11). Extensive search hasn't provided a solution yet. Seeking assistance and any help would be highly ...

Refreshing the database following a SELECT query on the php website

I recently attempted to create a PHP website where users can select components from a dropdown menu. The selected component is then fetched from the database using a SELECT query. Users can then update the values in this table using an UPDATE query. Each r ...

I am having trouble with the browser detection not accurately identifying the browser I am currently using

Currently, I am working on a JavaScript code that will simply display the name of the browser being used to view the web page. Despite me using Safari, none of the navigators seem to recognize it as the current browser. The information displayed in my brow ...

Changing the Color of Disabled Angular Material Buttons

<button _ngcontent-pse-c676="" mat-icon-button="" class="mat-focus-indicator setting_button mat-icon-button mat-button-base ng-star-inserted mat-button-disabled" ng-reflect-disabled="true" disabled="true" ...

The Alchemy feature on hover is not functioning

I am currently using alchemy.js to display a graph, but I am encountering issues with showing the "onMouseOver" caption of the graph's node. The console is displaying some errors which you can see here. Here is the code snippet: <html> < ...

Troubleshooting alignment problems with a responsive gallery (Bootstrap-gallery & justifyGallery)

Looking to showcase a gallery of images using jquery-justifyGallery and bootstrap-gallery. Want to display 4 images in a row, but running into issues when trying to display 5 images where the last image in the row ends up with a larger width. Bootstrap has ...

Can anyone suggest a method to set up a group chat without the need for a database?

I am interested in setting up a group chat where all messages and corresponding usernames are stored in a JSON file. However, achieving this without the use of node.js or MySQLi seems to be quite challenging. Currently, I am able to read the JSON file an ...

When PHPMailer is integrated with AJAX, it encounters issues and fails to function

Please note that despite reading other questions, none have provided a solution to my issue. Initially, I successfully tested the functionality on my localhost using AJAX and PHPMailer. The email was received as expected and the AJAX message indicated tha ...

Issue with $_FILES and $_POST data being empty during file uploads

There's a strange phenomenon I've observed when uploading videos - sometimes the $_POST and $_FILES array is completely empty. It's happened with a few of the videos I've tested, all of which are in the video/mp4 file format. <!DOCT ...

Stop the WebGL Three.js container from capturing scroll events

I am working on a full-screen three.js application which serves as the background and I am trying to add overlaid text that can be scrolled. However, my issue arises from the fact that the three.js WebGL container intercepts all scroll events and prevents ...

How can we avoid animations being interrupted by user interaction?

My webpage has an animation that runs smoothly on desktop, but stops as soon as I interact with the page on a touch device. I have tested this issue on Chrome and Safari on iPad. I'm curious if this behavior is intentional on the part of browser vend ...

What is the code to position the brand name to the right of a logo in HTML?

As I work on building my webpage, I am facing an issue where I want the brand name to appear directly next to the logo, on the right side. I have attempted to use the float-left property without success. I've included both the HTML and CSS code here. ...

Challenges arise when arranging div boxes vertically

Here is my code snippet: .blueleft { background-color: white; width: 300px; border: 25px #cee2e8; padding: 25px; margin: 40px; float: left; font-family: "berlin sans fb"; color: gray; font-size: 20px; text-align: c ...

List of random items:1. Red pen2

By using JavaScript, I want to generate a paragraph that contains a randomly ordered list of items (presented in paragraph format) for a basic website. The input would include: apples concrete a limited dose of contentment North Carolina The final ...