I have been searching extensively, but I can't seem to find a solution to my problem. Let me explain with a simple example. I have two child div
elements within a parent div
, and I want them to be centered horizontally inside the parent div
. Here is the link to the fiddle:
#container {
position: relative;
float: none;
margin: 0 auto;
border: solid blue 1px;
width: 100%;
}
.tile {
width: 20em;
height: 40em;
border:solid black 1px;
display: inline-block;
margin: 1.5em auto;
}
<div id="container">
<div class="tile">
<!--
When you remove this comment, the div shifts down and I do not understand what is causing that.
<h3>This Title Moves the div down. Why?</h3>-->
</div>
<div class="tile"></div>
</div>
Is there a simple solution that I am overlooking? I also have another question regarding the h3
tag. When the comment around the h3
tag is removed, the first div
shifts down. What characteristic of the h3
tag causes the div
to shift down and how can I prevent it?
Thank you for your assistance and explanations, and I apologize if this question has been asked before.