gpt4 book ai didi

css - css溢出的透明图像掩码

转载 作者:技术小花猫 更新时间:2023-10-29 11:41:15 26 4
gpt4 key购买 nike

我正在尝试实现等效的 css 属性:“溢出:透明 50%”。例如,如果我有这个:

<div style="border: 1px solid black; width: 200px; height: 200px; overflow: visible;">
<img src="img.png">
</div>

我希望 200x200 框中显示的图像部分正常。溢出 200x200 框的图像部分我想部分透明。也许有办法通过在主 div 周围定义四个 div 来做到这一点?我不确定执行此操作的简单方法。

+------------------+
| img overflow, |
| 50% transparent |
| +------------+ |
| | normal img | |
| +------------+ |
| |
+------------------+

图像的宽度和高度是预先知道的。 div 将附加一些 javascript 以允许通过拖动重新定位图像,因此 div 将充当视口(viewport),并且图像可以溢出到任何一侧。理想情况下需要在所有浏览器中工作。

最佳答案

不确定浏览器支持有多好,但像这样的东西应该让你开始:

 <style>
/* .container needs to be same size at img */
.container {width:400px; height:400px; background:#00f; opacity:0.5; margin:0 auto; position:relative; z-index:1;}
/* .container:before 1/4 img width, 1/2 img height, left 0, top 1/4 img, */
.container:before {content:""; display:block; width:100px; height:200px; position:absolute; left:0px; top:100px; z-index:15; background:#0f0; opacity:0.5;}
/* .container:before 1/4 img width, 1/2 img height, left 3/4 img, top 1/4 img */
.container:after {content:""; display:block; width:100px; height:200px; position:absolute; left:300px; top:100px; z-index:15; background:#0f0; opacity:0.5;}
/* .img would be your actual img at full size */
.img {display:block; width:400px; height:400px; position:absolute; z-index:10; background:#f00;}
/* .img:before same width as img, 1/4 height, top 0, left 0 */
.img:before {content:""; display:block; width:400px; height:100px; position:absolute; left:0px; top:0px; z-index:15; background:#00f; opacity:0.5;}
/* .img:after same width as img, 1/4 height, top 3/4 img height, left 0 */
.img:after {content:""; display:block; width:400px; height:100px; position:absolute; left:0px; top:300px; z-index:15; background:#00f; opacity:0.5;}
</style>
<div class="container">
<span class="img"></span>
</div>

编辑:忘记了 JS Fiddle 链接。 http://jsfiddle.net/BradleyStaples/rWzng/

关于css - css溢出的透明图像掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7701055/

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