I’m trying to line up three div tags that contain linked images for social icons on a portfolio website. I’ve been able to get them next to each other, but have only been able to get them evenly spaced across the container div, but I want them to be justified to the center. This is hard to explain, so I’ve attached a diagram to make it clearer. The issue may have something to do with the container divs I’ve used, but I’d love any help trying to solve this. Below is the code I’ve used, with very little removed so as to give further context to the problem:
<!DOCTYPE html>
<html lang="en">
<style>
html {
background-color: black;
padding: 0%;
}
body {
margin: 0%;
}
#leftWrapper {
color: white;
width: 30%;
height: 100%;
position: absolute;
margin: 0%;
padding: 0%;
text-align: center;
font-family: 'Trebuchet MS';
}
#leftVertWrapper {
position: absolute;
top: 50%;
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
#socialIconBigWrapper {
display: flex;
}
.socialIconWrapper {
flex: 20%;
padding: 5px;
box-align: 'justify-self';
}
.socialIcon {
width: 30%;
}
</style>
<body>
<div id="leftWrapper">
<div id="leftVertWrapper">
<div id="socialIconBigWrapper">
<div class="socialIconWrapper" style="float: left;">
<a style="text-decoration: none;" href="">
<img class="socialIcon" src="linkedinIcon.png">
</a>
</div>
<div class="socialIconWrapper" style="float: left;">
<a style="text-decoration: none;" href="">
<img class="socialIcon" src="twitterIcon.png">
</a>
</div>
<div class="socialIconWrapper" style="float: left;">
<a style="text-decoration: none;" href="">
<img class="socialIcon" src="githubIcon.png">
</a>
</div>
</div>
</div>
</div>
</body>
</html>
I’ve tried using tables and messing around with padding and margins, as well as using float: left;
and display: inline-block
. When using a table, the image size automatically centers itself by adding empty space to the sides of the image to make it wider. This achieves the first effect shown in the diagram, and no padding or margin changes can fix it. Using float just moves all of the images to one side of the div, without putting them next to each other, and display: inline-block; changed nothing.
2
Answers
Adding 2 lines of code to #leftWrapper will align the icons in the center:
Is this what you ment? I could not find the diagram you mentioned in the text.
I understand you are trying to center three div tags containing linked images for social icons on your portfolio website. I appreciate the effort you’ve put into explaining the issue. It sounds like you have been able to get the div tags next to each other but are having trouble centering them within the container div.
One solution you might want to try is adding display: flex to the container div’s CSS and then using justify-content: center to center the three div tags horizontally.
Here is a similar example
I recommend checking out this helpful resource: https://www.freecodecamp.org/news/how-to-center-anything-with-css-align-a-div-text-and-more/