为什么我不能在子div中正确对齐.png背景图像?

时间:2019-06-05 14:48:10

标签: html css

我在父div内还有2个左浮动50%宽度的div。左侧是文本,右侧只是我设置为background-attachment的背景图像(.png):已修复。问题在于此.png的背景位置基于父div,但不像我希望的那样占子div的50%。

我尝试了不同的背景位置以及背景尺寸,但无法正确显示。

.row-one{
	width: 100%;
	background-image: url("images/home/row-one.png");
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	display: flex;
}
.column-50{
	width: 50%;
	float: left;
	padding: 150px 0;
}
.sushi {
	width: 50%;
	float: left;
	background-image: url("images/home/row-one_img.png");
	background-position: center left;
	background-repeat: no-repeat;
	background-attachment: fixed;
}
<div class="row-one">
	<div class="column-50">
		<div class="mainTxt" data-aos="fade-up">
		<main>
			<p> text here </p>
		</main>
		</div>
	</div>
	<div class="sushi"></div>
	<div class="clear"></div>
</div>

我这样做是希望获得该背景.png的简单滚动效果。我希望背景.png出现在其div范围内。这是当前外观的屏幕截图:https://imgur.com/bxG1JrG

编辑:我发现背景附件:已修复;基于整个视口/屏幕尺寸。我不确定是否有一种方法可以基于特定的div?

0 个答案:

没有答案