在圆的节点和圆心设置图像

发布于 2025-01-10 05:21:51 字数 1149 浏览 0 评论 0原文

我在下面编写了 html 以显示下面的 7 个图像,

<html>
<head>
<style>
img {
  border-radius: 50%;
}
</style>
</head>
<body>

<h2>Rounded Images</h2>

    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    
    </body>
    </html> 

该 html 图像看起来如下

在此处输入图像描述

但希望此图像采用圆形格式,以便一个图像位于中心,所有其他图像围绕它 像圆圈一样,所以尝试添加下面的CSS

.Circle {
    width: 500px;
    height: 500px;
    background: aqua;
    border: 30px solid blue;
}

来创建圆圈,但是如何在节点上设置图像并在这个圆圈的中心?

I have written below html to show 7 images below is the html

<html>
<head>
<style>
img {
  border-radius: 50%;
}
</style>
</head>
<body>

<h2>Rounded Images</h2>

    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    <img src="img_avatar.png" alt="Avatar" style="width:200px">
    
    
    </body>
    </html> 

This images comes looks like below

enter image description here

but want this image in circular format so one image is in center and all other images surround it
like circle so tried adding below css

.Circle {
    width: 500px;
    height: 500px;
    background: aqua;
    border: 30px solid blue;
}

which created circle but how to set image on nodes and center in this circle ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丶视觉 2025-01-17 05:21:51

知道这个问题已经得到解答,我正在发布另一个答案

:root{
  --FullHeight:300px;/* [*] */
  --CircleHeight:75px;/* [*] */
  --totalImages:6;/* [*] */
}
img {
  border-radius: 50%;
}
.circle-container {
  position: relative;
  width: var(--FullHeight);
  height: var(--FullHeight);
  border-radius: 50%;
  padding: 0;
  list-style: none;
  border: solid 5px tomato;
}
.circle-container > * {

  position: absolute;
  top: 50%;
  left: 50%;
  margin: calc(0px - (var(--CircleHeight) / 2));
  width: var(--CircleHeight);
  height: var(--CircleHeight);
}
.circle-container > *:nth-of-type(1) {
  --cur:1;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(2) {
  --cur:2;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(3) {
  --cur:3;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(4) {
  --cur:4;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(5) {
  --cur:5;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(6) {
  --cur:6;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}/* [Duplicate this further more] */
.circle-container > *:nth-last-child {
  transform: rotate(0deg) translate(0px) rotate(0deg);
}


.circle-container img {
  max-width: 100%;
}
<h2>Rounded Images</h2>

<ul class='circle-container'>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
</ul>

这里像 /* [*] */ 这样的注释行意味着您必须正确地编辑

特征

  • 完全变量化
  • 圆形对齐正确

一支笔

Knowing that this question is answered,i am posting another answer

:root{
  --FullHeight:300px;/* [*] */
  --CircleHeight:75px;/* [*] */
  --totalImages:6;/* [*] */
}
img {
  border-radius: 50%;
}
.circle-container {
  position: relative;
  width: var(--FullHeight);
  height: var(--FullHeight);
  border-radius: 50%;
  padding: 0;
  list-style: none;
  border: solid 5px tomato;
}
.circle-container > * {

  position: absolute;
  top: 50%;
  left: 50%;
  margin: calc(0px - (var(--CircleHeight) / 2));
  width: var(--CircleHeight);
  height: var(--CircleHeight);
}
.circle-container > *:nth-of-type(1) {
  --cur:1;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(2) {
  --cur:2;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(3) {
  --cur:3;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(4) {
  --cur:4;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(5) {
  --cur:5;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}
.circle-container > *:nth-of-type(6) {
  --cur:6;/* [*] */
  transform: rotate(calc((360deg / var(--totalImages)) * (var(--cur) - 1)))
    translate(calc((var(--FullHeight) - var(--CircleHeight)) / 2)) 
    rotate(calc((0deg - (360deg / var(--totalImages)) * (var(--cur) - 1))));
}/* [Duplicate this further more] */
.circle-container > *:nth-last-child {
  transform: rotate(0deg) translate(0px) rotate(0deg);
}


.circle-container img {
  max-width: 100%;
}
<h2>Rounded Images</h2>

<ul class='circle-container'>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
  <li><img src='https://static.vecteezy.com/system/resources/previews/000/631/816/original/vector-blue-square-grid-mosaic-background-creative-design-templates.jpg'></li>
</ul>

here commented lines like /* [*] */ means you have to edit

Features

  • Fully variablized
  • Aligned in circle properly

A pen

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文