gpt4 book ai didi

CSS repeat-x 但只是图像中我想要的部分

转载 作者:行者123 更新时间:2023-11-28 09:31:26 26 4
gpt4 key购买 nike

我使用 background-size: cover 作为移动屏幕尺寸。

但是,对于桌面,如果我使用 background-size: cover ,我在图像中看不到猫。因为,我的图像的原始大小是高度比宽度长得多。

所以,我想只重复图像中没有出现猫的部分。但是,如果我使用 background-size: contain & background-repeat: repeat-x,我会看到以下内容:

current(图中的猫出现了3次。)

我想做的是类似下面的事情: what I want(只重复左右两边猫没有出现的部分。)

我在谷歌上搜索了很多,并阅读了 StackOverflow 中的几篇文章。但是,我找不到我想要的答案。如果您能给我任何建议,我将不胜感激!

* 以下是图片链接:

- [第一] https://postimg.cc/image/6pku8wgcr/

- [第二] https://postimg.cc/image/rz8gjr4d7/

- [原创猫背景] https://postimg.cc/image/hcenege97/

最佳答案

想法是使用多个背景叠加在一起来模拟这样的效果:

body {
margin:0;
min-height:500px;
height:100vh;
background:
/*the main background*/
url(https://picsum.photos/3744/5616?image=742) center,
/*repeat the left part*/
url(https://picsum.photos/3744/5616?image=742) 40% 50%,
url(https://picsum.photos/3744/5616?image=742) 30% 50%,
url(https://picsum.photos/3744/5616?image=742) 20% 50%,
url(https://picsum.photos/3744/5616?image=742) 10% 50%,
url(https://picsum.photos/3744/5616?image=742) 0% 50%,
/*repeat the right part*/
url(https://picsum.photos/3744/5616?image=742) 60% 50%,
url(https://picsum.photos/3744/5616?image=742) 70% 50%,
url(https://picsum.photos/3744/5616?image=742) 80% 50%,
url(https://picsum.photos/3744/5616?image=742) 90% 50%,
url(https://picsum.photos/3744/5616?image=742) 100% 50%;
background-repeat:no-repeat;
background-size:contain;
}

根据图像,您可以调整背景的百分比和数量以控制重复。这是对第一个代码的改进,通过减少重复的步骤来隐藏左侧不需要的部分:

全屏运行并比较这段代码和之前的代码

body {
margin:0;
min-height:500px;
height:100vh;
background:
/*the main background*/
url(https://picsum.photos/3744/5616?image=742) center,
/*repeat the left part more than the right*/
url(https://picsum.photos/3744/5616?image=742) 45% 50%,
url(https://picsum.photos/3744/5616?image=742) 40% 50%,
url(https://picsum.photos/3744/5616?image=742) 35% 50%,
url(https://picsum.photos/3744/5616?image=742) 30% 50%,
url(https://picsum.photos/3744/5616?image=742) 25% 50%,
url(https://picsum.photos/3744/5616?image=742) 20% 50%,
url(https://picsum.photos/3744/5616?image=742) 15% 50%,
url(https://picsum.photos/3744/5616?image=742) 10% 50%,
url(https://picsum.photos/3744/5616?image=742) 5% 50%,
url(https://picsum.photos/3744/5616?image=742) 0% 50%,
/*repeat the right part*/
url(https://picsum.photos/3744/5616?image=742) 60% 50%,
url(https://picsum.photos/3744/5616?image=742) 70% 50%,
url(https://picsum.photos/3744/5616?image=742) 80% 50%,
url(https://picsum.photos/3744/5616?image=742) 90% 50%,
url(https://picsum.photos/3744/5616?image=742) 100% 50%;
background-repeat:no-repeat;
background-size:contain;
}

更新

这是带有您的图片的代码:

body {
margin:0;
min-height:500px;
height:100vh;
background:
/*the main background*/
url(/image/76q2w.png) center,
/*repeat the left part*/
url(/image/76q2w.png) 40% 50%,
url(/image/76q2w.png) 30% 50%,
url(/image/76q2w.png) 20% 50%,
url(/image/76q2w.png) 10% 50%,
url(/image/76q2w.png) 0% 50%,
/*repeat the right part*/
url(/image/76q2w.png) 60% 50%,
url(/image/76q2w.png) 70% 50%,
url(/image/76q2w.png) 80% 50%,
url(/image/76q2w.png) 90% 50%,
url(/image/76q2w.png) 100% 50%;
background-repeat:no-repeat;
background-size:contain;
}

关于CSS repeat-x 但只是图像中我想要的部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51692948/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com