【发布时间】:2019-12-19 19:53:56
【问题描述】:
我有一个部分是所有 p 和 img 元素,它们都排在同一个地方,但是 img 会离开屏幕,而 p 不会。我的 body css 中有 box-sizing:border-box,我尝试添加对齐内容和对齐项目,我添加了宽度:100% 和溢出:auto,但似乎都没有修复它,不确定我在搞砸什么。感谢您的任何帮助。我还应该提到它主要是一个较小的移动窗口,因为我有更大屏幕的媒体查询。
#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>
【问题讨论】:
-
尝试将 img 宽度设置为自动。您也可以尝试将溢出设置为隐藏
-
将示例中的图像替换为基于 url 的占位符图像,以便其他人可以看到效果。示例:
<img src="https://via.placeholder.com/150/" alt="Story 1">
标签: html css image off-screen