如何在div设置为不透明度时设置Overflow =可见

我有1 div1 image标记,一个在另一个上。 Divimage小。 对于div我设置了overflow=visible 。 我的问题是,当我插入一个图像到图像标签时,通过div溢出的内容应该是这样的opacity=0.5

我想我的div看起来像这样

对我来说,它显示这样..任何帮助

<div style="border-style: solid; border-width: 2px; height: 5cm; width: 8cm;top: 20px; left: 20px; position: relative;  overflow: visible;" id="divimg">
  <img src="https://stepupandlive.files.wordpress.com/2014/09/3d-animated-frog-image.jpg" id="displayimg" style="height: 7cm; width: 10cm;" />
</div>

这是您的要求的演示。

.outter_div{width:400px; height: 200px;position: relative;}
.outter_div:after{content:"";border:50px solid rgba(255,255,255,0.5);position: absolute; top: 0;width: 300px;height: 100px;}
img{width: 100%;position:}
 <div class="outter_div">
       <img src="https://stepupandlive.files.wordpress.com/2014/09/3d-animated-frog-image.jpg"/>
</div>

如果您可以将HTML更改为如下所示:

<div id="holder">
  <div id="overlay">          
  <img src="https://stepupandlive.files.wordpress.com/2014/09/3d-animated-frog-image.jpg" id="displayimg"  />

    </div>    
    <div id="box"></box>  

</div>

CSS:

#holder {
    width:500px;
    height:250px;
    position:relative;
    overflow:hidden;

}

#overlay {
    width:500px;
    height:250px;
    opacity:0.5;

}
#displayimg {

    width:500px;
    height:250px;

}
#box {
    width:250px;
    height:100px;
    background-color:black;
     position:absolute;
    left:200px;
    top:70px;
    overflow:hidden;

}
#box #ima {

    position:absolute;
     width:500px;
    height:250px;
    display:block;
}

和小JQuery魔术:

$('#box').append('<img src="https://stepupandlive.files.wordpress.com/2014/09/3d-animated-frog-image.jpg" id="ima"  /> ');

$('#ima').offset($('#holder').offset());

$( "#box" ).draggable();

  $( "#box" ).draggable({

      drag: function() {
      $('#ima').offset($('#holder').offset());
      }

    });     

既然你提到了拖动,我已经在小提琴中导入了JQuery UI:http://jsfiddle.net/y3c41d10/1/

对于调整大小,你将不得不做一些计算,但它是可行的,我希望...


这就是我想到的:

<div class="container">
    <div class="main">
        <div class="sub">This is a text</div>
    </div>
</div>


.main {
    background-image:url(http://lorempixel.com/g/200/200/);
    position: relative;
}
.container {
    width:300px;
    height:300px;
}
.sub {
    text-align: center;
    padding:15px;
    border: solid 30px rgba(255, 255, 255, 0.5);
    color:white;
}

这里是JSFiddle演示

链接地址: http://www.djcxy.com/p/87591.html

上一篇: How to give opacity for div when it is set Overflow=visible

下一篇: Swift: Prevent ABPeoplePickerNavigationController from Closing