简体   繁体   English

如何在css3中结束一列图像

[英]how to end a column of images in css3

I have the following code HTML 我有以下代码HTML

<div id="images" class="img"/>
 <img src="spiderman.png" alt=""/>
 <img src="superman.png" alt="" height="25%" width="25%"/>
 <img src="batman.png" alt="" />
</div>

css 的CSS

.img {
  position: absolute;  
  right: 15%; 
  top: 30%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;

.img2 {
box-shadow: 0px 0px 5px #fff;
  position: absolute;  
  right: 15%; 
  top: 30%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

JavaScript 的JavaScript

(function() {

   function keyDown(event) {
     if (event.keyCode == 65) {
       if (document.getElementsByClassName("img").length > 0) {
         document.getElementsByClassName("img")[0].className = "img2"
       } else {
         document.getElementsByClassName("img2")[0].className = "img"
       }
     }
   }

   document.addEventListener('keydown', keyDown);
 })();

which outputs 哪个输出 在此处输入图片说明

This code aligns three images in a column and when i press the key 'a' it highlights those, the only problem i am having is the column doesn't seem to end and i do not know how to solve this. 这段代码将一列中的三个图像对齐,当我按“ a”键突出显示这些图像时,我遇到的唯一问题是该列似乎没有结束,而且我也不知道如何解决这个问题。

the images div: 图片div:

<div id="images" class="img"/>

is ending when it shouldn't. 在不应该结束的时候结束。 remove the slash and give it a run 删除斜线并运行

<div id="images" class="img">
    <img src="spiderman.png" alt=""/>
    <img src="superman.png" alt="" height="25%" width="25%"/>
    <img src="batman.png" alt="" />
</div>

The issue seems to be with the superman.png image. 问题似乎出在superman.png图片上。 It is using the original height and width of the image. 它使用图像的原始高度和宽度。 So it shrinks the image for the display but still thinks it is large when measuring, hence the larger open space in the column. 因此它缩小了显示图像,但在测量时仍然认为它很大,因此列中的空白空间更大。

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

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