首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带掩码的响应div

带掩码的响应div
EN

Stack Overflow用户
提问于 2017-05-27 21:27:07
回答 1查看 497关注 0票数 0

基于Mask position incorrect when I stop using a background image上的掩码思想,我尝试了一个水平的、同样高度响应的div测试。

结果,掩模无法扩展以覆盖div。

Html:

代码语言:javascript
复制
<div class="IndexBanners">
<div class="bannerimages effect first">
<iframe class="embed-responsive-item" frameborder="0" src="https://www.youtube.com/embed/GfaiXgY114U" height="100%" width="100%"></iframe>
<div class="black-box">
  <h2>Watch Video</h2>
</div>
</div>
<div class="bannerimages effect">
<a href="https://placehold.it"><img src="http://placehold.it/795x436"></a>
<div class="black-box">
  <h2>View News</h2>
</div>
</div>

CSS:

代码语言:javascript
复制
.IndexBanners {
    display: flex;
    margin-top: 20px;
}

.bannerimages {
    flex: 1 0 0;
}

img {
    max-width: 100%;
    height: auto;
    vertical-align: top;
}

.black-box {
    text-align: center;
    font-size: 16px;
    color: #fff;
    background-color: rgba(00, 00, 00, 0.8);
    width: 49%;
    height: 66%;
    opacity: 0.75;
    transition: all 0.5s ease-in-out;
    position: absolute;
    top: 20px;
}

.black-box:hover {
    opacity: 0.0;
    transition: all 0.5s ease-in-out;
}

h2 {
    padding-top: 23%;
    margin: 0;
}

@media (max-width:600px) {
.IndexBanners {
    display: block;
}
.first {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
}
.first iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
}

我设置的测试小提琴是这样的:https://jsfiddle.net/3hekqxf7/,您将从小提琴中看到,实际上只有一个大小的口罩正确地覆盖了div。考虑到我使用了掩码的百分比值,我会期望它和它正在掩蔽的div一起展开/收缩。

问题是,你到底该如何在一个有反应的div上得到一个响应性的掩膜?!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-27 22:23:41

使覆盖与视频父级响应的方法是在父服务器上使用position: relative,然后在覆盖层上使用position: absolute; top: 0; left: 0; right: 0; bottom: 0;,并且它将符合父节点的任何形状。

代码语言:javascript
复制
.IndexBanners {
  display: flex;
  margin-top: 20px;
}

.bannerimages {
  flex: 1 0 0;
  position: relative;
}

img {
  max-width: 100%;
  height: auto;
  vertical-align: top;
}

.black-box {
    text-align: center;
    font-size: 16px;
    color: #fff;
    background-color: rgba(00,00,00,0.8);
    
    
    opacity: 0.75;
    transition: all 0.5s ease-in-out;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
}

.black-box:hover {
    opacity: 0.0;
    transition: all 0.5s ease-in-out;
}

h2 {
    padding-top: 23%;
    margin: 0;
}

@media (max-width:600px) {
  .IndexBanners {
    display: block;
  }
  .first {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
  }
  .first iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
}
代码语言:javascript
复制
<div class="IndexBanners">
  <div class="bannerimages effect first">
    <iframe class="embed-responsive-item" frameborder="0" src="https://www.youtube.com/embed/GfaiXgY114U" height="100%" width="100%"></iframe>
    <!--a href="http://placehold.it"><img src="http://placehold.it/795x436"></a-->
    <div class="black-box">
        <h2>Watch Video</h2>
    </div>
  </div>
  <div class="bannerimages effect">
    <a href="http://placehold.it"><img src="http://placehold.it/795x436"></a>
    <div class="black-box">
        <h2>View News</h2>
    </div>
  </div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44221756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档