Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cover a div

Tags:

html

Let's say we have a div as follow:

<div class="post">Variable text</div>

The text can be any longer. So it could be 3 characters, 150 or 300. The div has a border of border: 1 px solid black over a background: white. Is there any way to create another div (with position relative or absolute i guess) that completely covers this div so that the text is unreadable?

like image 461
Shoe Avatar asked Jan 26 '11 16:01

Shoe


3 Answers

<div class="post" style="position:relative">
     Variable text
     <div style="position:absolute;top:0;left:0;width:100%;height:100%;background-color:white"></div>
</div>

Something like that could work, you may have to play with the z-index to make sure your white box is on top. Basically, that inner div starts at the top left corner of the outer div and is the same size as it.

like image 149
Jay K Avatar answered Nov 13 '22 03:11

Jay K


CSS:

.outer { 
  position:relative;
  z-index:10;
}
.inner {
  position:absolute;
  left:0;
  top:0;
  width:100%;
  height:100%;
  z-index:20;
 }

CSS (image replacement):

.outer { 
  text-indent:-9999em;
  height:0;
  padding:100px 0 0 0;
  width:100px;
  background-image:url(100x100.jpg);
}

HTML:

<div class="outer">
  <div class="inner"></div>
  Text to Replace
</div>
like image 5
Dirk Diggler Avatar answered Nov 13 '22 03:11

Dirk Diggler


What are you trying to achieve? Any reasons you need another div?

If you're just trying to hide the data why don't you just:

<div class="post" style="background-color:black;">Variable text</div>

And ensure your text is also 'black'

like image 1
m.edmondson Avatar answered Nov 13 '22 05:11

m.edmondson