[英]Absolute element inside div won't appear on top of other elements
I'm creating a "border" image for my div and instead of making it a border image (because I can't seem to be able to do it for this image, I am creating a separate image to be placed on top of my iframe.) 我正在为div创建一个“边框”图像,而不是使其成为边框图像(因为我似乎无法对此图像进行处理,因此我将创建一个单独的图像放置在我的顶部iframe中。)
I've looked around and you can't place a bg image ontop of the content so I had to use: 我环顾四周,您无法在内容上放置bg图片,因此我不得不使用:
position: absolute;
z-index: 100;
But it still won't appear / appear on top... 但是它仍然不会出现/出现在顶部...
Any ideas? 有任何想法吗? Here is the JSFiddle: http://jsfiddle.net/0hapk48z/5/
这是JSFiddle: http : //jsfiddle.net/0hapk48z/5/
Here you are your fiddle running: 在这里,您正在演奏小提琴:
http://jsfiddle.net/0hapk48z/9/ http://jsfiddle.net/0hapk48z/9/
What I made is to solve syntax errors and give to .border a height of 1000 px 我所做的是解决语法错误,并将.border的高度设置为1000 px
.border { height: 1000px; }
You can put the exact height do you need 您可以放所需的确切高度
.border
has no height which is why nothing is displaying. .border
没有高度,因此没有显示任何内容。
Add a height and it displays. 添加高度并显示。
http://jsfiddle.net/0hapk48z/8/ http://jsfiddle.net/0hapk48z/8/
You would actually be better using an image element instead of background-image CSS. 实际上,使用图像元素代替背景图像CSS会更好。 That way you don't need to enter the height and width, it should just load at the natural dimensions supplied:
这样,您无需输入高度和宽度,它只需按提供的自然尺寸加载即可:
http://jsfiddle.net/0hapk48z/14/ http://jsfiddle.net/0hapk48z/14/
You need to shrink wrap the container with display:inline-block
then size it accordingly (allowing padding for the image to display properly) and use height:100%
on the overlay. 您需要使用
display:inline-block
收缩包装容器,然后相应调整其大小(允许填充以正确显示图像),并在覆盖层上使用height:100%
。
.votd {
padding: 0;
width: 860px;
text-align: center;
position: relative;
display: inline-block;
padding-top: 34px;
padding-bottom: 22px;
}
.border {
width: 860px;
position: absolute;
background: url(http://i.imgur.com/16pm0Ms.png);
background-repeat: no-repeat;
z-index: 100;
height: 100%;
top: 0;
left: 0;
}
iframe {
width: 800px;
height: 600px;
border: 2px solid darken(#CFBA6B, 20);
margin: 0 auto;
display: block;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.