在 考虑以下情况:您有一个 嵌套在 ,如这段代码所示: 默认情况下, 将与 选项 1:行高操纵 设置行高子 等于 选项 2:绝对定位 将绝对定位应用于 请参阅所提供的有关理解垂直对齐的文章,了解更多详细信息和其他技术。<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 */
}
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3