简体   繁体   English

将图像和图形标签内的锚标签对齐

[英]Aligning an image and an anchor tag inside a figure tag

I am stuck and out of ideas, I tried to achieve the following with flexbox and failed. 我陷入困境,没有想法,我试图通过flexbox实现以下目标,但失败了。

What I am trying to achieve is to have an img tag centered inside a figure tag and have an a tag which contains an another img tag(like a button to show a different version of the first image) align at the bottom right corner of the same figure tag. 我想实现是有一个img一个内部居中标签figure标签,并有a包含了另一个标签img标签(如按钮来显示不同版本的第一个图像)在的右下角对齐相同的figure标签。
Let me try to explain with an image: 让我尝试用图像来解释: 说明

Here A is our figure tag, B is our first image and C is our anchor tag which itself contains another image. 这里A是我们的身材标签, B是我们的第一张图片, C是我们的锚标签,它本身包含另一个图像。
The A is sized at 350px by 280px A的尺寸为350px x 280px
The B is a transparent png of varying sizes, but always a lot smaller then the A B是大小可变的透明png,但总是比A小很多
The C contains a 20px by 20px image C包含20px x 20px的图片
The container div#gallery contains many figure tags 容器div#gallery包含许多figure标签

Here is what I have right now. 这就是我现在所拥有的。

 <div id="gallery" style="display: flex; flex-wrap: wrap; justify-content: center;"> <figure style="background-color:#2A3132; width: 350px; height: 280px"> <img src="https://via.placeholder.com/110x110"> <a href="#"> <img src="https://via.placeholder.com/30"> </a> </figure> </div> 

What I understand is that we can not have C inside A because then it misaligned the B 我了解的是,我们不能在A内包含C ,因为那样会使BB对齐

I have used position:absolute for positioning that small image. 我已经使用position:absolute来定位那个小图像。 As mentioned by OP there is no chance for overlapping the images so it won't be problematic. 如OP所述,没有机会重叠图像,因此不会有问题。

 #gallery { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; } .wrapper { background-color: #2A3132; width: 350px; height: 280px; position: relative; display: flex; justify-content: center; align-items: center; } .sm-img { position: absolute; bottom: 0; right: 0; height: 30px; margin: 0 10px 10px 0; width: 30px; } 
 <div id="gallery"> <figure class="wrapper"> <img src="https://via.placeholder.com/110x110"> <a class="sm-img" href="#"> <img src="https://via.placeholder.com/30"> </a> </figure> </div> 

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

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