如何调整来自 API 调用的图像?

huangapple go评论78阅读模式
英文:

how do i fit images from an api call?

问题

My first time posting anything here so if I am missing something please tell me! Ok, so my problem is that the images in my categories page don't fit each other and do not align anymore. This happened after I learned a little JavaScript and got the images from an API call. Now they don't look so good anymore... especially in mobile view. How can I make it so they are all the same size? I'm totally a rookie by the way.
Here is the link to my page: https://lovely-croissant-3cceca.netlify.app/

I tried fixing it with CSS but it doesn't "react" anymore when I change something. The mobile view in the categories page, the images are too high. But when I try to lower them in the media queries, the desktop version also changes. I know it's likely something with the

I made when I was trying out JavaScript. I also can't change the name "test" to something else because everything gets disturbed...

英文:

My first time posting anything here so if i am missing something please tell me! Ok, so my problem is that the images in my categories page don't fit eachother and does not align anymore. This happened after I learned a little javascript and got the images from an API call. Now they don't look so good anymore... especially in mobile view. How can I make it so they are all the same size? I'm totally a rookie by the way.
Here is the link to my page: https://lovely-croissant-3cceca.netlify.app/

I tried fixing it with CSS but it doesn't "react" anymore when I change something. The mobile view in the categories page, the images are to high. But wwhen I try to lower them in the media queries the desktop version also changes. I know it likely something with the <div id="test"> i made when I was trying out javascript. I also cant change the name "test" to something else, because the everything gets disturbed...

答案1

得分: 0

以下是翻译好的部分:

  1. The output's what matters, not the fact that the images are called through API, we can address the result with CSS.

    输出是最重要的,而不是通过API调用图像的事实,我们可以使用CSS来处理结果。

  2. The film titles push the images down, because they are in the same container, so we have to give them a height.

    电影标题将图像推下来,因为它们位于同一个容器中,所以我们必须为它们设置高度。

  3. The ratio of the images differs, so you could use object-fit: cover to crop the images at a maximum size of the smallest image's height.

    图像的比例不同,因此您可以使用object-fit: cover将图像裁剪到最小图像高度的最大尺寸。

  4. On mobile: you need the overflow to be set to visible, and take out the padding from the .container-child too (there are multiple extra spaces otherwise), and add only to the parent.

    在移动设备上:您需要将overflow设置为visible,并将.container-child中的padding删除(否则会有多余的空白),仅添加到父容器。

  5. Something like this, would do it:

    类似这样的代码可以实现:

.container-child p {
    height: 50px;
    text-align: center;
    display: block;
}
/* 从这里开始是响应式代码 */
@media (max-width:1624px){
    .container-child img {
        object-fit: cover;
        max-width: 500px;
        max-height: 709px; /* 最小图像的高度 */
        width: 100%;
        height: 100%;
    }
}
@media (max-width: 768px) {
    .container-child {
        padding-top: 0em; 
        display: inline-block;
        text-align: center;
    }
    #test {
        margin-top: 130px;
        display: inline-block;
        text-align: center;
    }
    html, body {
        overflow: visible;
        background: #000;
    }
}

请注意,以上是代码部分的翻译。如果您有其他问题或需要进一步的帮助,请随时提出。

英文:

The output's what matters, not the fact that the images are called through API, we can address the result with CSS.

The film titles push the images down, because they are in the same container, so we have to give them a hight.

The ratio of the images differs, so you could use object-fit: cover to crop the images at a maximum size of the smallest image's height.

On mobile: you need the overflow to be set to visible, and take out the padding from the .container-child too (there are multiple extra spaces otherwise), and add only to the parent.

Something like this, would do it:

    .container-child p {
       height: 50px;
       text-align: center;
       display: block;
   }
    /*from here the responsive code*/
    @media (max-width:1624px){
        .container-child img {
          object-fit: cover;
          max-width: 500px;
          max-height: 709px; /*the smallest image*/
          width: 100%;
          height: 100%;
        }
    }
    @media (max-width: 768px) {
    .container-child {
        padding-top: 0em; 
        display: inline-block;
        text-align: center;
       }
       #test {
        margin-top: 130px;
        display: inline-block;
        text-align: center
       }
       html, body {
        overflow: visible;
        background: #000;
       }
    }

huangapple
  • 本文由 发表于 2023年5月20日 20:46:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76295299.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定