---
title: "lightbox + div"
author: "PBFox"
date: "2008-01-14T17:08:00Z"
tags: []
slug: "lightbox-div"
draft: false
lastmod: "2008-01-14T17:08:00Z"
id: 479237
url: "https://developerwork.iteye.com/blog/479237"
---

做lightbox时候，如果是另外一个页面的话，我用的是redbox，而在同一页面中的div做了好长时间也没做出来，要是单单一个div到也还好办，关键这个div还要用到本页面其他的数据，没办法在网上搜到了这段纯css控制的，挺不错的。  
&lt;html&gt;  
&lt;head&gt;  
&lt;title&gt;LIGHTBOX EXAMPLE&lt;/title&gt;  
&lt;style&gt;  
.black\_overlay{  
display: none;  
position: absolute;  
top: 0%;  
left: 0%;  
width: 100%;  
height: 100%;  
background-color: black;  
z-index:1001;  
\-moz-opacity: 0.8;  
opacity:.80;  
filter: alpha(opacity=80);  
}  
.white\_content {  
display: none;  
position: absolute;  
top: 25%;  
left: 25%;  
width: 50%;  
height: 50%;  
padding: 16px;  
border: 16px solid black;  
background-color: white;  
z-index:1002;  
overflow: auto;  
}  
&lt;/style&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;p&gt;This is the main content. To display a lightbox click &lt;a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'"&gt;here&lt;/a&gt;&lt;/p&gt;  
&lt;div id="light" class="white\_content"&gt;This is the lightbox content. &lt;a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"&gt;Close&lt;/a&gt;&lt;/div&gt;  
&lt;div id="fade" class="black\_overlay"&gt;&lt;/div&gt;  
&lt;div style="height:1090px"&gt;&lt;/div&gt;  
&lt;/body&gt;  
&lt;/html&gt;