What is the best way to position a logo at the center of a circle

My latest school project involves creating a contact page for my website, and I want to add social media icons inside circular containers. Below is the CSS code snippet I have used:

.ul2{
  display: flex;
}
.ul2 li{
  position: relative;
  display: block;
  color: #666;
  font-size: 30px;
  height: 60px;
  width: 60px;
  background: #171515;
  line-height: 60px;
  border-radius: 50%;
  margin: 0 15px;
  cursor: pointer;
  transition: .5s;
}
.ul2 li:before{
  position: absolute;
  content: '';
  top: 0;
  left: 0;
  height: inherit;
  width: inherit;
  /* background: #d35400; */
  border-radius: 50%;
  transform: scale(.9);
  z-index: -1;
  transition: .5s;
}
.ul2 li:nth-child(1):before{
  background: #4267B2;
} 
...
... (CSS code continues)
<html>
<head>
  <script src="https://kit.fontawesome.com/a076d05399.js"></script>
</head>

<body>
  <ul class="ul2">
    <li><i class="fab fa-facebook-f"></i></li>
    <li><i class="fab fa-twitter"></i></li>
    ... (social media icon classes continue)
  </ul>
</body>
</html>

As you can see in this image link, the icons are displayed within the circles with some hover effects applied.

To improve the design further, I introduced a new ul class but need guidance on centering the logos accurately.

Answer №1

If you want to center the icons in all of your lists (.ul2 li), simply add "text-align: center".

The code provided appears to vertically center the items, unlike the image that was sent. To vertically and horizontally center an item, you can use flexbox styling. When using flexbox for items in a row (setting display: flex defaults to a row direction), "justify-content" aligns horizontally while "align-items" aligns items vertically.

display: flex;
justify-content: center;
align-items: center;

.ul2{
  display: flex;
}
(remaining CSS styles...)
<head>
  <script src="https://kit.fontawesome.com/a076d05399.js"></script>
  </head>
  <ul class="ul2">
    <li><i class="fab fa-facebook-f"></i></li>
    <li><i class="fab fa-twitter"></i></li>
    <li><i class="fab fa-instagram"></i></li>
    <li><i class="fab fa-linkedin-in"></i></li>
    <li><i class="fab fa-youtube"></i></li>
  </ul>

Answer №2

The below style should be added to the existing ul2 li

.ul2 li{
 display: flex;
 align-items:center;
 justify-content:center;
}
.ul2{
  display: flex;
}
.ul2 li{
  position: relative;
  display: flex;
  color: #666;
  font-size: 30px;
  height: 60px;
  width: 60px;
  background: #171515;
  line-height: 60px;
  border-radius: 50%;
  margin: 0 15px;
  cursor: pointer;
  transition: .5s;
  align-items:center;
  justify-content:center;
}
.ul2 li:before{
  position: absolute;
  content: '';
  top: 0;
  left: 0;
  height: inherit;
  width: inherit;
  /* background: #d35400; */
  border-radius: 50%;
  transform: scale(.9);
  z-index: -1;
  transition: .5s;
}
.ul2 li:nth-child(1):before{
  background: #4267B2;
} <!-- Additional CSS properties and animations are presented -->
<head>
  <script src="https://kit.fontawesome.com/a076d05399.js"></script>
</head>
<ul class="ul2">
<li><i class="fab fa-facebook-f"></i></li>
<!-- Remaining list items with Font Awesome icons -->
</ul>

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

Is there a way to prevent the text next to these FontAwesome icons from moving whenever the icon itself changes?

I am currently working on creating a unique custom checkmark using FontAwesome in my project. Below is the snippet of HTML and CSS style code that I am using: .check { font-size: 1.25rem; cursor: pointer; } .check-unselected { color: #4E44 ...

Take the attention away from the canvas

Is there a way to shift focus away from the canvas and onto input fields in my HTML code? Right now, the canvas is holding onto focus even when I'm clicking on text inputs. This prevents me from typing anything into them. Ideally, I'd like for t ...

JavaScript Button with the Ability to Input Text in a TextArea?

For instance, imagine a scenario where you click on a button and it then displays various options for you to select from. Whatever option you pick will be automatically inserted into the text area. ...

Modifying the color of the highlighted selection in a dropdown select box

Is it possible to change the blue highlight on this dropdown to gray? Check out this demo of a select box I am aiming to alter the highlight color to gray, can someone help me achieve this? select { border: 0; color: #EEE; background: transparen ...

Issues with ASP.net rendering stylesheets

Here is the layout of my Index.cshtml page: <html> <head runat="server"> <link href="~/Content/index.css" rel="stylesheet" type="text/css" /> <asp:ContentPlaceHolder ID="HeadContent" runat="server" /> </head> < ...

Access several different dynamic URLs through a single Ajax request

I have a scenario where I am showing multiple dynamic links within the same div. The first link works perfectly fine with ajax loading the content, but the subsequent links do not work. How can I make it so that the content of all links can be loaded withi ...

Manipulating strings within strings with JavaScript

It's been a strange discovery I made while working with JavaScript. Whenever I try to assign a two-word string to a CSS property, like setting the fontFamily property of an HTML element to "Arial Black", it ends up looking something like thi ...

Controlling the page scroll when adding data using jQuery

I am encountering an issue with a webpage that displays around 20 pictures in separate divs stacked vertically. Below these 20 pictures, there is a "show more" button that, when clicked, loads another set of 20 pictures and appends them to the existing dat ...

Create a circular div that fills in when hovered over using CSS

I attempted to create an interesting effect when hovering over a circular div, but I struggled to figure out how to fill it in with the same round shape. Currently, the fill is in a square shape, but I am looking to have it match the shape of the div (whi ...

Navigating the screen reader with the cursor位

Site Design Challenge I recently discovered that the master/detail design of my website is not very accessible. The main view features a column chart where each column represents a different month. Clicking on one of these columns reveals details in a nes ...

Combining CSS3 transform scale with jQuery UI resizable for enhanced functionality

I am currently working on factoring in the impact of scaling an element while utilizing jquery ui resizable. Although there have been some discussions regarding css3 transform issues with resizing/dragging, I have not come across a solution that works eff ...

Using an onClick event along with jQuery to change the CSS class style of another div

After searching extensively without success, I decided to register and ask my first question here. Hopefully, someone can provide a solution: My goal is to create a set of five buttons (divs) with onClick events that will show five different divs. I' ...

Concealing table columns using JavaScript - adapt layout on the fly

I am currently implementing a responsive design feature on my website, where I need to hide certain columns of a table when the viewport size decreases beyond a specific point. Initially, I tried using .style.visibility = "collapse" for all <tr> elem ...

Tips for generating AJAX requests directly from HTML documents

Hey there! I'm fairly new to JavaScript and have a question that might seem silly to some. How exactly can I invoke a function from a Coffeescript file within my HTML code? I'd like to give users the option to choose the language in which they v ...

List items not appearing inline

I'm having an issue with displaying a list of movies from my database. Instead of showing inline as intended, they are appearing vertically. I've tried using both inline-block and inline for the li elements, but so far nothing has worked. Any ass ...

What is the best way to ensure that the width of a div fills its parent container?

I need my divs(.give, .sep, .take) to completely fill the width of its parent container (.trade). This is the HTML code: <div class="trade"> <div class="give"></div> <div class="sep"></div> ...

Steps to activate a particular Bootstrap tab upon clicking a hyperlink

Trying to implement a Bootstrap tab panel in the following manner: <ul class="nav nav-tabs" role="tablist"> <li class="nav-item"> <a class="nav-link active" data-toggle="tab" href ...

Neither the Ajax nor the jQuery validation plugin are functioning simultaneously

My code is intended to validate all user fields before inserting data into the database. However, when I include validation code and AJAX code simultaneously, it does not work. On the other hand, both codes work fine individually. If I comment out the AJAX ...

"Troubleshooting: Issue with ng-click in AngularJS not triggering ng-show

I can't figure out why my ng-click isn't showing the ng-show message. I've tried searching for a solution but no luck. Here is my controller function: $scope.showLogoutMessage = function() { $scope.logoutmsg = true; }; This is my Logi ...

Transferring information from a component that includes slot content to the component within the slot content

This task may seem complex, but it's actually simpler than it sounds. I'm struggling with the correct terminology to enhance the title. I need to transfer data from a component that includes slot content to that slot content component. In partic ...