如何将背景图像宽度设置为边到边

舒巴克·塔吉

我正在尝试进行视差滚动,并且一切正常。但我想要的是背景图像使用页面的完整宽度(如边到边),但背景两侧还留有一点边距。

这是我的代码:

.container{
	max-width: 100%;
	margin: 0 auto;
	background: aqua;
	font-size: 24px;
	padding: 25px;
}
.parallax{
	width: 100%;
	background: url('Baradari.jpg') no-repeat center;
	background-size: cover;
	background-attachment: fixed;
	height: 500px;
}
.parallax2{
	width: 100%;
	background: url('rumi-darwaza.jpg') no-repeat center;
	background-size: cover;
	background-attachment: fixed;
	height: 500px;
}
.parallax3{
	width: 100%;
	background: url('rumi-darwaza.jpg') no-repeat center;
	background-size: cover;
	background-attachment: fixed;
	height: 500px;
}
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Parallax</title>
		<link rel="stylesheet" href="style.css">
	</head>
	<body>
		<div class="container">
			<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
		</div>
		<div class="parallax">

		</div>
		<div class="container">
			<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
		</div>
		<div class="parallax2">

		</div>
		<div class="container">
		<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
		</div>
		<div class="parallax3">

		</div>
		<div class="container">
			<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
	Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
	It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
	It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
		</div>
	</body>
</html>

我尝试在所有视差类中设置position: absolute;设置left: 0px;但它会使所有图像聚集在一起并且写入的部分被隐藏。请帮忙!

短剑
body { margin:0; }

应该解决你的问题

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章