Home >Web Front-end >CSS Tutorial >How to Arrange Clickable Images in a Circle Around a Center Image?

How to Arrange Clickable Images in a Circle Around a Center Image?

DDD
DDDOriginal
2024-12-10 17:59:15787browse

How to Arrange Clickable Images in a Circle Around a Center Image?

Position Icons into Circle

Question:

How can I position multiple images in a circle around another image, making them all clickable links?

Answer:

Solution 1 (Modern)

Using HTML, CSS, and JavaScript:

  1. Generate HTML with image links based on an array.
  2. Use CSS to position images on a circle within a container.
  3. Adjust container size based on circle radius and image size.

Solution 2 (Old)

Using CSS transforms:

  1. Create a wrapper div for the circle container.
  2. Position images absolutely in the center of the wrapper.
  3. Apply chained CSS transforms to rotate and translate images to desired angles.

Code Snippet:

.circle-container {
  width: 24em;
  height: 24em;
  position: relative;
}

.circle-container a {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.deg0 img {
  transform: rotate(0deg);
}

.deg45 img {
  transform: rotate(45deg);
}

.deg90 img {
  transform: rotate(90deg);
}

The above is the detailed content of How to Arrange Clickable Images in a Circle Around a Center Image?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn