简体   繁体   English

如何组合 3 个背景图像,其中一个被拉伸,两个用于顶部和底部?

[英]How to combine 3 background images where one is stretched and two are for top and bottom?

I want to create a custom scrollbar with the ::-webkit-scrollbar* selectors, but I think the answer can also be used for any other container.我想用 ::-webkit-scrollbar* 选择器创建一个自定义滚动条,但我认为这个答案也可以用于任何其他容器。

 ::-webkit-scrollbar { width: 20px; } ::-webkit-scrollbar-track { background: url('https://svgshare.com/i/bqE.svg') right 2px center no-repeat; background-size: 10px 100%; width: 15px; } ::-webkit-scrollbar-thumb { background-image: url('https://svgshare.com/i/brF.svg'), url('https://svgshare.com/i/brD.svg'), url('https://svgshare.com/i/bqv.svg'); background-position: right top, right bottom, right 15px; background-repeat: no-repeat, no-repeat, no-repeat; background-size: 15px 15px, 15px 15px, 15px 100%; } #scroll { height: 400px; width: 200px; border: 1px solid black; overflow-y: scroll; } div > div { height: 1000px; }
 <div id="scroll"> <div>Inner Container</div> </div>

The example is a little problematic because of the missing images.由于缺少图像,该示例有点问题。 The goal is to have a top and a bottom area of 15x15px where the "top"/"bottom"-background is shown.目标是有一个 15x15px 的顶部和底部区域,其中显示“顶部”/“底部”背景。

The problem is: The streched image in the middle need to have a 15px offset from top AND 15px from bottom.问题是:中间的拉伸图像需要从顶部偏移 15 像素,从底部偏移 15 像素。 It's easy to have the top OR bottom offset, but I don't know how to get both.顶部或底部偏移很容易,但我不知道如何同时获得。 The middle image does have curves (comic look) and has to perfectly fit (as it's the case when using border-image*).中间的图像确实有曲线(漫画外观)并且必须完美贴合(就像使用 border-image* 时的情况一样)。

Is there any way to accomplish this?有什么办法可以做到这一点吗? I also tried to solve the problem with border-image* properties, but this does not seem to work for scrollbars.我还尝试使用 border-image* 属性解决问题,但这似乎不适用于滚动条。

EDIT: Here is an example of the images.编辑:这是图像的示例。 I don't know where to upload svg graphics for embedding.我不知道从哪里上传 svg 图形进行嵌入。

EDIT 2: Added images.编辑 2:添加图像。 You can the the problem at the bottom of the scrollbar.您可以在滚动条底部解决问题。 The stretched, middle part, needs an offset of 15px from top and bottom.拉伸的中间部分需要从顶部和底部偏移 15px。

图像示例

Update your code like below:更新您的代码,如下所示:

 ::-webkit-scrollbar { width: 20px; } ::-webkit-scrollbar-track { background: url('https://svgshare.com/i/bqE.svg') right 2px center no-repeat; background-size: 10px 100%; width: 15px; } ::-webkit-scrollbar-thumb { background: url('https://svgshare.com/i/brF.svg') top, url('https://svgshare.com/i/bqv.svg') center, url('https://svgshare.com/i/brD.svg') bottom; background-repeat: no-repeat; background-size: 100% 15px,100% calc(100% - 30px); } #scroll { height: 400px; width: 200px; border: 1px solid black; overflow-y: scroll; } div > div { height: 1000px; }
 <div id="scroll"> <div>Inner Container</div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM