英文:
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
英文:
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
以下是翻译好的部分:
-
The output's what matters, not the fact that the images are called through API, we can address the result with CSS.
输出是最重要的,而不是通过API调用图像的事实,我们可以使用CSS来处理结果。
-
The film titles push the images down, because they are in the same container, so we have to give them a height.
电影标题将图像推下来,因为它们位于同一个容器中,所以我们必须为它们设置高度。
-
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
将图像裁剪到最小图像高度的最大尺寸。 -
On mobile: you need the
overflow
to be set tovisible
, and take out thepadding
from the.container-child
too (there are multiple extra spaces otherwise), and add only to the parent.在移动设备上:您需要将
overflow
设置为visible
,并将.container-child
中的padding
删除(否则会有多余的空白),仅添加到父容器。 -
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;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
- css
- html
- javascript
评论