【问题标题】:why images are going off the page, and no other content is为什么图像离开页面,而没有其他内容
【发布时间】: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 的占位符图像,以便其他人可以看到效果。示例:&lt;img src="https://via.placeholder.com/150/" alt="Story 1"&gt;

标签: html css image off-screen


【解决方案1】:

将您的 #story img width 更改为 calc() 值,以适应将其推过的 80px padding。 p>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 2011-04-11
    • 2012-04-25
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多