繁体   English   中英

使用HTML和CSS将图像放置到Circle中

[英]Position images into Circle with HTML and CSS

我需要所附图片的每个元素都是交互式的,即能够为其分配自己的CSS类。 在此处输入图片说明

我将图像切成3个部分,如下所示。 原始图片中圆圈的高度和宽度为476px x 476px。

我想知道如何安排这些切片来复制附加的图像。

这有可能吗?

这是每个切片的HTML,供可能对尝试提供帮助的任何人使用。

<img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6a5746fb9a13cdd54e0/1462544038103/a-slice.png">
<img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6af746fb9a13cdd551f/1462544047951/b-slice.png">
<img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6b4746fb9a13cdd553c/1462544052730/c-slice.png">

这不是重复的问题,因为“重复的”问题基于使用svg创建元素。 这个问题基于使用图像元素并将它们组织成圆形图案。

并非没有使用一些疯狂的特定定位...

https://jsfiddle.net/968zsj53/

<div class="container">
<img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6a5746fb9a13cdd54e0/1462544038103/a-slice.png">
<img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6af746fb9a13cdd551f/1462544047951/b-slice.png">
<img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6b4746fb9a13cdd553c/1462544052730/c-slice.png">
</div>

.container {
  width:500px;
}

.container img {
  max-width:100%;
  position:absolute;
}

.container img:nth-child(1){
  left:0;
  top:0;
}

.container img:nth-child(2){
  left:244px;
  top:0;
}

.container img:nth-child(3){
  left:38px;
  top:301px;
}

问题是缺少信息,但是一种简单的方法是显示+边距:

不确定是否符合您的要求

 img:last-of-type { display: table;/* or block, table is for the tease */ margin: -64px 33px 0 } 
 <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6a5746fb9a13cdd54e0/1462544038103/a-slice.png"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6af746fb9a13cdd551f/1462544047951/b-slice.png"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6b4746fb9a13cdd553c/1462544052730/c-slice.png"> 

对于菜单,您可以保留主意并使用包装器遮盖区域

 a:last-child img { margin: -64px 33px 0 } nav { border: solid; height: 470px; width: 470px; border-radius: 50%; position: relative; } nav:before { content: ''; position: absolute; height: 217px; width: 216px; background: gray; border-radius: 50%; top: 127px; left: 127px; } 
 <nav> <a href="a"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6a5746fb9a13cdd54e0/1462544038103/a-slice.png"> </a> <a href="b"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6af746fb9a13cdd551f/1462544047951/b-slice.png"> </a> <a href="c"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6b4746fb9a13cdd553c/1462544052730/c-slice.png"> </a> </nav> 

试试这个简单的事情,可能对您有帮助

 div { position: relative; } #three { left: 32px; position: absolute; top: 296px; } 
 <div> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6a5746fb9a13cdd54e0/1462544038103/a-slice.png"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6af746fb9a13cdd551f/1462544047951/b-slice.png"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6b4746fb9a13cdd553c/1462544052730/c-slice.png" id="three"> </div> 

 .circle { position: absolute; width: 120px; height: 120px; display: block; } .circle img:nth-child(1) { position: absolute; width: 100%; left: 0; } .circle img:nth-child(2) { position: absolute; width: 100%; left: 125px; } .circle img:nth-child(3) { position: absolute; width: 204px; left: 21px; height: auto; top: 154px; } 
 <div class="circle"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6a5746fb9a13cdd54e0/1462544038103/a-slice.png"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6af746fb9a13cdd551f/1462544047951/b-slice.png"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6b4746fb9a13cdd553c/1462544052730/c-slice.png"> </div> 

您将不得不摆弄定位。 我已经在jsfiddle中为您设置了。

看一下: https : //jsfiddle.net/x3rbqsbm/

您要在此处查找的东西是保存容器,然后元素上的后续位置随即消失。

 .circle { height: 475px; position: relative; width: 475px; } .circle > img { position: absolute; -webkit-transition: transform 0.15s linear 0s; -ms-transition: transform 0.15s linear 0s; transition: transform 0.15s linear 0s; } .circle > img:hover { -webkit-transform: scale(1.1); -ms-transform: scale(1.1); transform: scale(1.1); } .circle > img:nth-child(1) { left: 0; top: 0; } .circle > img:nth-child(2) { right: 0; top: 0; } .circle > img:nth-child(3) { bottom: 0; left: 50%; transform: translateX(-50%); } .circle > img:nth-child(3):hover { -webkit-transform: scale(1.1) translateX(-50%); -ms-transform: scale(1.1) translateX(-50%); transform: scale(1.1) translateX(-50%); } 
 <div class="circle"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6a5746fb9a13cdd54e0/1462544038103/a-slice.png"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6af746fb9a13cdd551f/1462544047951/b-slice.png"> <img src="http://static1.squarespace.com/static/56e975d8f8baf3c1d69ac026/t/572ca6b4746fb9a13cdd553c/1462544052730/c-slice.png"> </div> 

 <!DOCTYPE html> <html> <title>W3.CSS</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"> <body class="w3-container"> <h2>Image in a Circle</h2> <p>You do not need boostrap, you can use w3-schools libraries instead</p> <img src="http://i.stack.imgur.com/schtq.png" class="w3-circle" alt="" style="width:50%"> </body> </html> 

暂无
暂无

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

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