How can I position several <img> elements into a circle around another and have those elements all be clickable links as well? I want it to look like the picture below, but I have no idea how to achieve that effect.

Is this even possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
2020 solution
Here’s a more modern solution I use these days.
I start off by generating the HTML starting from an array of images. Whether the HTML is generated using PHP, JS, some HTML preprocessor, whatever… this matters less as the basic idea behind is the same.
Here’s the Pug code that would do this:
The generated HTML looks as follows (and yes, you can write the HTML manually too, but it’s going to be a pain to make changes afterwards):
In the CSS, we decide on a size for the images, let’s say
8em. The--mitems are positioned on a circle and it’s if they’re in the middle of the edges of a polygon of--medges, all of which are tangent to the circle.If you have a hard time picturing that, you can play with this interactive demo which constructs the incircle and circumcircle for various polygons whose number of edges you pick by dragging the slider.
This tells us that the size of the container must be twice the radius of the circle plus twice half the size of the images.
We don’t yet know the radius, but we can compute it if we know the number of edges (and therefore the tangent of half the base angle, precomputed and set as a custom property
--tan) and the polygon edge. We probably want the polygon edge to be a least the size of the images, but how much we leave on the sides is arbitrary. Let’s say we have half the image size on each side, so the polygon edge is twice the image size. This gives us the following CSS:See the old solution for an explanation of how the transform chain works.
This way, adding or removing an image from the array of images automatically arranges the new number of images on a circle such that they’re equally spaced out and also adjusts the size of the container. You can test this in this demo.
OLD solution (preserved for historical reasons)
Yes, it is very much possible and very simple using just CSS. You just need to have clear in mind the angles at which you want the links with the images (I’ve added a piece of code at the end just for showing the angles whenever you hover one of them).
You first need a wrapper. I set its diameter to be
24em(width: 24em; height: 24em;does that), you can set it to whatever you want. You give itposition: relative;.You then position your links with the images in the center of that wrapper, both horizontally and vertically. You do that by setting
position: absolute;and thentop: 50%; left: 50%;andmargin: -2em;(where2emis half the width of the link with the image, which I’ve set to be4em– again, you can change it to whatever you wish, but don’t forget to change the margin in that case).You then decide on the angles at which you want to have your links with the images and you add a class
deg{desired_angle}(for exampledeg0ordeg45or whatever). Then for each such class you apply chained CSS transforms, like this:where you replace
{desired_angle}with0,45, and so on…The first rotate transform rotates the object and its axes, the translate transform translates the object along the rotated X axis and the second rotate transform brings back the object into position.
The advantage of this method is that it is flexible. You can add new images at different angles without altering the current structure.
CODE SNIPPET
Also, you could further simplify the HTML by using background images for the links instead of using
imgtags.EDIT: example with fallback for IE8 and older (tested in IE8 and IE7)