如何设置div的不透明度Overflow = visible

时间:2015-08-21 09:46:04

标签: javascript jquery html css

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

i want my div look like this

对我来说它显示如下..任何帮助

<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>

3 个答案:

答案 0 :(得分:2)

如果您可以将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/

为了调整大小,你必须做一些计算,但它是可行的,我希望......

答案 1 :(得分: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;
}

Here is the JSFiddle demo

答案 2 :(得分:1)

以下是您的要求的演示。

&#13;
&#13;
.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:}
&#13;
 <div class="outter_div">
       <img src="https://stepupandlive.files.wordpress.com/2014/09/3d-animated-frog-image.jpg"/>
</div>
&#13;
&#13;
&#13;

JSFiddle demo