css溢出的透明图像掩码

mji*_*son 5 css overflow opacity

我正在尝试实现等效的css属性:"overflow:transparent 50%".例如,如果我有这个:

<div style="border: 1px solid black; width: 200px; height: 200px; overflow: visible;">
 <img src="img.png">
</div>
Run Code Online (Sandbox Code Playgroud)

我希望200x200盒子中显示的图像部分正常.溢出200x200盒子的图像部分我希望部分透明.也许有办法通过在主要div周围定义四个div来做到这一点?我不确定一个简单的方法来做到这一点.

+------------------+
| img overflow,    |
| 50% transparent  |
|  +------------+  |
|  | normal img |  |
|  +------------+  |
|                  |
+------------------+
Run Code Online (Sandbox Code Playgroud)

图像宽度和高度是手头已知的.div将附加一些javascript以允许通过拖动重新定位图像,因此div将像视口一样运行,并且图像可能在任何一侧溢出.理想情况下,需要在所有浏览器中工作.

小智 2

不确定浏览器支持有多好,但是这样的事情应该让你开始:

 <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>
Run Code Online (Sandbox Code Playgroud)

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