h5开发网站-css实现页面的背景固定定位

一、需求:

在页面滚动时,背景图片保持不变,而不是跟随滚动。

在这里插入图片描述

二、解决方式:

使用背景固定定位,只需要在CSS中增加一个background-attachment: fixed;属性即可。

具体代码:

<div class="item_right">
	<img src="images/[email protected]">
</div>


<style>
	.item_right {
      
      
		width: 60.75%;
		height: 500px;
		position: absolute;
		right: 0;
		background-image: url(../images/[email protected]);
		background-repeat: no-repeat;
		background-size: 60.75% 100%;
		background-attachment: fixed;   /* 这一行是重点 */
		background-position: top right;
	}
	 .item_right img {
      
      
		max-width: 100%;
		height: auto;
		visibility: hidden;
	}
</style>

ok~

猜你喜欢

转载自blog.csdn.net/weixin_48596030/article/details/132684442