I am trying to place some text inside a square div. The only problem is that it shifts the div that the text is in down a lot. Does anyone know how I can get the div back to its original position?
Here is the html:
<div id="squarecontainer">
<div id="square1">
<p>Easy to Manage</p>
</div>
<div id="square2">
</div>
<div id="square3">
</div>
</div>
Here is the css:
#squarecontainer{
text-align: center;
}
#square1{
display: inline-block;
position: relative;
margin-right: 100px;
height: 310px;
width: 310px;
margin-top: 72px;
background-color: #fff;
}
#square2{
display: inline-block;
position: relative;
height: 310px;
width: 310px;
margin-top: 72px;
background-color: #fff;
}
#square3{
display: inline-block;
position: relative;
margin-left: 100px;
height: 310px;
width: 310px;
margin-top: 72px;
background-color: #fff;
}
#square1
is the div that shifts really far down when I added the "Easy to Manage" text.
Fiddle link demonstrating the problem: http://jsfiddle.net/jhunlio/RgywE/
Basically, by giving an element absolute positioning, it is no longer being taken into account when positioning the rest of the page. It will take up its alloted space in its set position no matter what.
If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).
Yes, you can directly add content text into a div tag, although using p tags would be preferable in most circumstances.
I found the solution. By adding vertical-align: top;
it moved the div back. don't know why it worked, but it did.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With