最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make a div appear all over the site? - Stack Overflow

programmeradmin1浏览0评论

I'm trying to make a 50% opacity <div> appear all over the site, I gave it position absolute and width, height of 100%. but its still appears only parts of the site, if you scroll down, it doesn't cover the rest of the site.

<div style="width:100%; height:100%; margin:0; top:0; left:0; background:#000; position: absolute;">
   loading..
</div>

What can I do?

I'm trying to make a 50% opacity <div> appear all over the site, I gave it position absolute and width, height of 100%. but its still appears only parts of the site, if you scroll down, it doesn't cover the rest of the site.

<div style="width:100%; height:100%; margin:0; top:0; left:0; background:#000; position: absolute;">
   loading..
</div>

What can I do?

Share Improve this question edited Aug 22, 2012 at 20:33 Steve Czetty 6,2289 gold badges40 silver badges49 bronze badges asked Jul 6, 2010 at 10:17 WEBProjectWEBProject 1,3456 gold badges16 silver badges33 bronze badges 2
  • Code sample would help a lot here... – Chris Commented Jul 6, 2010 at 10:21
  • <div style="width:100%; height:100%; margin:0; top:0; left:0; background:#000; position: absolute;"> loading.. </div> this is the div.. im trigering it after a 'submit' – WEBProject Commented Jul 6, 2010 at 10:21
Add a comment  | 

3 Answers 3

Reset to default 13

Use position: fixed; instead of position: absolute;:

<div style="width: 100%; height: 100%; margin: 0em;
            left: 0em; top: 0em; background: black;
            position: fixed;">Loading ...</div>

This works too:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test</title>
<style type="text/css">
    #big {
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        background: #000;
    }
</style>
</head>
    <body>
        <div id="big"></id>
    </body>
</html>

Setting top and bottom should do the trick (it also works with position: fixed).

Use z-index, example:

<style scoped="scoped" type="text/css">
	
	.imgWrap {
		position: relative;
		width: 25%x;
	}
	
	.imgDescription {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		background: rgba(0, 0, 0, 0.75);
		color: #fff;
		visibility: hidden;
		opacity: 0;
		height: 400px;
		width: 400px;
		padding: 5px 5px 5px 5px;
		z-index: 100;
	}
	
	.imgWrap:hover .imgDescription {
		visibility: visible;
		opacity: 1;
	}
</style>

<table style="width: 100%;">
  <tbody>
    <tr>
      <td style="width: 100%;">
        <div class="imgWrap">
		  <p style="text-align: left;"><strong>Text</strong></p>
		  <p>&nbsp;</p>
		  <div class="imgDescription">
		  <ul style="text-align: left;">
		  <li>Description...</li>							
		  </ul>
		</div>
	  </div>
     </td>
    </tr>
  </tbody>
</table>

发布评论

评论列表(0)

  1. 暂无评论