简体   繁体   English

图像/ DIV - 无法弄清楚如何让带有标题的图像留在移动视口中

[英]Image / DIV - Can't figure out how to get image with caption to stay in mobile viewport

I run a tiny little website for myself.我为自己经营一个小小的网站。 It's mainly a hobby site.它主要是一个爱好网站。 It uses WP 6.1 and DIVI as a theme.它使用 WP 6.1 和 DIVI 作为主题。

On a recent post ( you can see here ), I had an author want to have captions under some photos.在最近的一篇文章中( 你可以在这里看到),我有一位作者想要在一些照片下加上标题。 I tried putting the photos in a DIV and using float on the DIV.我尝试将照片放在 DIV 中并在 DIV 上使用浮动。 It mainly works.它主要起作用。

The problem is this: In a mobile device view (iphone portrait or landscape), some of the photos extent to the right beyond the view port.问题是这样的:在移动设备视图(iphone 纵向或横向)中,一些照片超出了视口的右侧。 And one, the puppy photo at the top, sticks off to the left partly outside the viewport.其中一张是顶部的小狗照片,部分位置偏向左侧,超出了视口。

I'm so close to achieving what I want: The ability to embed an image with caption, and then align both where I want (normally would just put style="align:left;" on the IMG tag.我非常接近实现我想要的:能够嵌入带有标题的图像,然后将两者对齐到我想要的位置(通常只需将 style="align:left;" 放在 IMG 标签上。

Anyways, kinda pulling my hair out.无论如何,有点把我的头发拉出来。 The thing is, in Firefox responsive view for iphone 11, some of the photos look like they fit, others don't.问题是,在 iPhone 11 的 Firefox 响应式视图中,有些照片看起来很合适,有些则不合适。 But on a real iphone (14), most of them are extending beyond the actual viewport.但是在真正的 iphone (14) 上,它们中的大多数都超出了实际的视口。

So I think I'm missing something that would tell the image part of my code to SHRINK responsively, but it's not really working fully.所以我想我遗漏了一些东西,它会告诉我的代码的图像部分响应地收缩,但它并没有真正完全发挥作用。

I think it may be the margin: auto part.我认为这可能是 margin: auto part。 But I'm not sure how to fix this.但我不确定如何解决这个问题。

Can anyone offer any thoughts?谁能提供任何想法? Here's a little snippet of the DIV that encloses the images, but you can also just visit the link, too and see the source.这是包含图像的 DIV 的一小段,但您也可以只访问链接并查看源代码。

<div style="margin: 0px auto; width: 600px; padding: 15px; border: 1px solid black; text-align: center;"><img src="https://crazydogliving.com/wp-content/uploads/2023/01/Delilah_collage_1.jpg" /><strong>
First Christmas one year later. Nap time!</strong></div>

I'd really be grateful.我真的很感激。

I was expecting the images on mobile inside the child DIV containing the photo and caption to responsively scale and fit in the viewport on mobile.我期待移动设备上包含照片和标题的子 DIV 中的图像能够响应地缩放并适合移动设备的视口。

The problem is the width.问题是宽度。 If u use max-width the img still in the screen.如果你使用 max-width img 仍然在屏幕上。 "max-width:100%;" “最大宽度:100%;”

    <div style="margin: 0px auto; width: 600px; padding: 15px; border: 1px solid black; text-align: center;max-width: 100%"><img src="https://crazydogliving.com/wp-content/uploads/2023/01/Delilah_collage_1.jpg" style="max-width: 100%"/><strong>
    First Christmas one year later. Nap time!</strong></div>

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

相关问题 我不知道如何让带有图像的 div 服从父 div 的高度约束 - I can't figure out how to get div with image to obey the height constrains of the parent div 无法弄清楚如何为网站正确覆盖带有图像的 div - Can't figure out how to cover a div with an image correctly for website 无法弄清楚如何将背景图片放入我的 <div> 工作权 - Can't figure out how to get a background image into my <div> working right 无法弄清楚如何在桌面上将此按钮和 header 或此图像在移动设备上居中 - Can't figure out how to center this button & header on desktop or this image on mobile 无法弄清楚如何使用边距将图像居中:自动 - Can't figure out how to center image with margin: auto CSS:我需要以一种非常特定的方式安排&lt;div&gt;,但无法弄清楚(看图片) - CSS:I need to arrange < div > s in a very specific way but can't figure it out (look at the image) 调整图像大小以保持在视口内 - Resize an image to stay within the viewport 如何使图像栏保持在手机菜单的最上方? - How can I make an image bar to stay on top with the menu on mobile? Bootstrap 4 中的中心图形图像和标题 - Center figure image and caption in Bootstrap 4 使用 Python 3.7 和 Selenium,我不知道如何解决我的代码中的视口元素问题 - Using Python 3.7 and Selenium, I can't figure out how to troubleshoot my code for out of Viewport elements
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM