简体   繁体   English

如何使图像集群与CSS中的中心对齐?

[英]How to make a cluster of images aligned to the center in CSS?

So, I have a group of images arranged in a circle, and I'm trying to get them to stay in one place, regardless of how the screen is resized. 因此,我将一组图像排列成一个圆圈,无论屏幕如何调整大小,我都试图将它们保留在一个位置。 The images are a series of petals arranged like a flower, and at first I had each petal placed by using absolute positioning and pixels away from the edges. 图像是一系列像花朵一样排列的花瓣,起初,我使用绝对定位和远离边缘的像素来放置每个花瓣。 However, when I resize the image, the petals would all move to the left or right. 但是,当我调整图像大小时,花瓣将全部向左或向右移动。 Then I placed the petals using percentage away from the edges. 然后,我将花瓣放在离边缘一定距离的位置。 Now each individual petal moves away from the center or towards the center. 现在,每个花瓣都离开中心或朝中心移动。 I tried to create a div to keep the image as a whole clustered and positioned, but I haven't had any luck with that. 我试图创建一个div来使图像整体上保持群集和定位,但是我对此没有任何运气。 Any advice on how I can keep the petals in place? 关于如何将花瓣固定在位的任何建议? Here's what the petal code looks like: 花瓣代码如下所示:

basics {
position: absolute;
left: 47.5%;
right: 52.5%;
}

there are twelve petals, each with a slightly different position. 有十二个花瓣,每个花瓣的位置略有不同。 Does anyone know how I can keep them in one place on the screen? 有谁知道我如何将它们放在屏幕上的某个位置?

The easy way out would be to create a block with a position absolute, and position the images inside with their own absolute positioning. 最简单的方法是创建一个具有绝对位置的块,并以自己的绝对位置将图像定位在内部。 This would force the images to base their current position on the block itself. 这将迫使图像将其当前位置基于块本身。

Does that make sense? 那有意义吗?

Here's the HTML and CSS: 这是HTML和CSS:

Here's a fiddle: https://jsfiddle.net/g90gbdrp/1/ 这是一个小提琴: https : //jsfiddle.net/g90gbdrp/1/

  div { border: 3px solid #000000; height: 200px; width: 200px; position: absolute; left: calc(50% - 100px); top: calc(50% - 100px); } img { width: 50px; height: 50px; position: absolute; } #one { top: -2em; left: -2em; } #two { top: -2em; right: -2em; } #three { bottom: -2em; left: -2em; } #four { bottom: -2em; right: -2em; } 
 <div> <img src="http://pngimg.com/upload/cat_PNG1631.png" id="one" /> <img src="http://pngimg.com/upload/cat_PNG1631.png" id="two" /> <img src="http://pngimg.com/upload/cat_PNG1631.png" id="three" /> <img src="http://pngimg.com/upload/cat_PNG1631.png" id="four" /> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM