Aligning a Vertically Within a Consider the following situation: you have a nested within a By default, the will align to the bottom-left corner of the Option 1: Line-Height Manipulation Set the line-height of the child to be equal to the height of the Option 2: Absolute Positioning Apply absolute positioning to the Refer to the provided article on understanding vertical alignment for further details and additional techniques.<div
id="theMainDiv"
style="
border:solid 1px gray;
cursor:text;
width:400px;
padding:0px;"
>
<span
id="tag1_outer"
style="
background:#e2e6f0;
padding-right:4px;
padding-left:4px;
border:solid 1px #9daccc;
font:normal 11px arial;
color:#3c3c3c"
>as</span>
</div>
#theMainDiv {
height: 20px; /* Set the div height for reference */
}
#tag1_outer {
line-height: 20px;
}
#theMainDiv {
position: relative; /* Apply relative positioning to the div */
}
#tag1_outer {
position: absolute;
top: 50%;
margin-top: -10px; /* Half the height of the child span */
}
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3