Reputation: 182
I'm trying to write a div on div and I'm stuck trying to get the title right on the line of the div. Does anyone know how to do this?
Upvotes: 0
Views: 527
Reputation: 24549
You may be interested in looking into position
of en element.
For example, using the middle box as the 'middle' div, and a displaced
div for this title;
.outer {
margin: 0 auto;
height: 400px;
width: 80%;
border: 5px solid red;
position: relative;
}
.middle {
height: 200px;
width: 80%;
border: 5px solid blue;
/*centering the blue div to middle of the red box*/
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.displaced {
font-size: 30px;
/*needed to put the green div up onto the line*/
position: absolute;
left:50%;
transform: translate(-50%, -50%);
border: 2px solid green;
}
<div class="outer">
<div class="middle">
<div class="displaced">
this will be on the line
</div>
</div>
</div>
For more information please read the w3c documents relating to this positioning.
Further Reading
Upvotes: 1