0
I’m trying to position a text box over an image through the z index, to get something like this: http://postimg.org/image/an6lkq9gf/
Now the text appears after the image (since it is in a 100% width div). I wanted the text to appear superimposed on the image.
What am I doing wrong? Thank you
My code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
#intro {
width:100%;
float:left;
padding-right:3%;
padding-top:3%;
padding-bottom:3%;
background-repeat:no-repeat;
background-size:100%;
position:relative;
z-index:50;
}
.txt_ilustracao {
display:block;
width:38%;
margin: 7% 3% 3% 7%;
float:right;
color:black;
background-color: rgba(255, 255, 255, 0.6);
padding:5%;
position:relative;
z-index:100;
}
.txt_ilustracao1 {
font-size:2.5em;
margin-top: 10%;
margin-bottom:3%;
text-align:center;
}
.txt_ilustracao2 {
font-size:1.8em;
margin-top:9%;
text-align:center;
}
</style>
<div id="intro"><img src="IMGS/index_fundo_pb.jpg"></div>
<div class="txt_ilustracao">
<div class="txt_ilustracao1">
asdfgcvhbjklçjh erdtfyguhijopoçlikujhtgrfed<br>
asdfgcvhbjklçjh erdtfyguhijopoçlikujhtgrfed <br>
asdfgcvhbjklçjh erdtfyguhijopoçlikujhtgrfed</div>
<div class="txt_ilustracao2">asdfgcvhbjklçjh erdtfyguhijopoçlikujhtgrfed
asdfgcvhbjklçjh erdtfyguhijopoçlikujhtgrfed.<br><br>
asdfgcvhbjklçjh erdtfyguhijopoçlikujhtgrfed</div>
</div> <!-- intro -->
Have you tried with
background-image
?– Lucas
Yes, but in this case I was interested in having it with the z-index. Thank you
– David Monteiro
And what’s going on?
– Lucas
Now the text appears after the image (since it is in a 100% width div). I wanted the text to appear superimposed on the image.
– David Monteiro
In the css class
.txt_ilustracao
, swap theposition:relative
forposition:absolute
and testing.– Rafael Withoeft
So it was. Thanks Rafael! Now the only problem is the text box. I wanted it to be aligned on the right side (assigns it the float:right). However it is "stuck" on the left side. Any suggestions? Thanks
– David Monteiro
To use z-index the classes should not be inside each other, use a div pro background and one for box, the contents of the box you leave inside the same box div, then the text will float along with the box.
– haykou
For the text box to be aligned to the right use
right: 0px;
– Carlos
Thank you Carlos, it worked! D
– David Monteiro