div on top of iframe

2019-04-05 13:02发布

Im looking for a solution to place a div (100% screen width and lets say 20% height) on top of iframe which is 100% screen width and 100% screen height It should look like this:

__________________________
||      On top DIV       ||
||_______________________||
|                         |
|         Iframe          |
|                         |
|_________________________|

标签: css html iframe
3条回答
神经病院院长
2楼-- · 2019-04-05 13:09

Super simple stuff..

put an iframe, and a header div inside one container div.

set position:relative on the container, and position:absolute and top:0 on the header div.

that should do it.

HTML:

<div class="holder">
   <iframe class="frame"></iframe>
   <div class="bar"></div>
</div>​

CSS:

.holder{
    width: 400px;
    height:300px;
    position:relative;
}
.frame{
    width: 100%;
    height:100%;
}
.bar{
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:40px;
}

fiddle

查看更多
姐就是有狂的资本
3楼-- · 2019-04-05 13:13

It should be possible, what's the problem?

Make sure you have the position style set to absolute (or fixed, depending on your need) and set the proper z-index if necessary. Also adjust width and height as needed.

查看更多
对你真心纯属浪费
4楼-- · 2019-04-05 13:27

The concept of Rodik answer is good but the implementation is buggy.

  1. put an iframe, and a header div inside one container div.

  2. set position:relative on the container, and position:absolute and top:0 on the header div.

In HTML code

<div class="holder">
    <iframe class="frame"></iframe>
    <div class="bar"></div>
</div>

In CSS

.holder{
    width: 400px;
    height:300px;
    position:relative
}
.frame{
    width: 100%;
    height:100%;
    background-color:blue;
}
.bar{
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:40px;
    background-color: red;
    }

http://jsfiddle.net/eayr9pup/2/

查看更多
登录 后发表回答