简体   繁体   English

为什么图像从页面上消失,而没有其他内容

[英]why images are going off the page, and no other content is

I have a section that is all p and img elements, they both line up at the same place, but the img will go off screen while the p does not.我有一个部分全部是 p 和 img 元素,它们都排在同一个地方,但是 img 会离开屏幕而 p 不会。 I have box-sizing:border-box in my body css, I've tried adding justify content and align items, I've added the width:100% and overflow:auto, and none of it seems to fix it, not sure what I am messing up.我的 body css 中有 box-sizing:border-box,我尝试添加对齐内容和对齐项目,我添加了宽度:100% 和溢出:自动,但似乎都没有修复它,不确定我在搞什么。 Thank you for any help.感谢您的任何帮助。 I should also mention it is mainly a smaller mobile window I am trying to make this work for, as I have media queries for larger screens.我还应该提到它主要是一个较小的移动窗口,我正在尝试使其工作,因为我有针对较大屏幕的媒体查询。

 #story{ background: linear-gradient(#4B7992, #090D19); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; } #story h1{ flex:100%; padding:30px 0px; } #story h2{ background: #4B7992; padding: 20px 15px 30px; text-align: center; } #story img{ padding: 30px 80px 20px; width: 100%; overflow: auto; } #story p { padding:15px 80px 16px; line-height: 30px; }
 <section id="story"> <h1>THE STORY</h1> <h2>From the creators...</h2> <article> <img src="images/story1.png" alt="Story 1"> <p>Based on ....</p> <img src="images/story2.jpg" alt="Story 2"> <p>More....</p> <img src="images/story3.png" alt="Story 3"> <p>End...</p> </article> </section>

Change your #story img width to a calc() value to accommodate for the 80px padding that is pushing it over.#story img 宽度更改为calc()值以适应将其推过的80px 填充

#story img{
    padding: 0px 80px 0px;
    width: calc(100% - 80px);
    overflow: auto;
}

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

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