Html 如何:当高度为0px时,在边框顶部上方溢出文本,就像在边框底部溢出一样

Html 如何:当高度为0px时,在边框顶部上方溢出文本,就像在边框底部溢出一样,html,css,menu,alignment,border,Html,Css,Menu,Alignment,Border,当高度设置为height:0px时,是否可以像在边框底部下方一样,在边框顶部上方显示垂直对齐文本 HTML: 巧克力很容易在边框底部下方对齐。马铃薯确实在li上方对齐,但边框顶部也在其后(?)对齐 TL;DR:我是否可以让下面这把小提琴中的按钮正确对齐 奇怪的愿望(嗯;)要做到这一点,实际上元素的边框在元素外部呈现,因此没有直接的方法可以做到这一点,但是如果您想让文本垂直位于边框中间,那么您需要在标记和CSS中更改一些内容 首先,使用一个简单的span标记包装单词,然后在CSS中使用以下规则

当高度设置为
height:0px时,是否可以像在
边框底部下方一样,在
边框顶部上方显示
垂直对齐
文本

HTML:

巧克力很容易在
边框底部下方对齐。马铃薯确实在
li
上方对齐,但
边框顶部
也在其后(?)对齐


TL;DR:我是否可以让下面这把小提琴中的
按钮正确对齐

奇怪的愿望(嗯;)要做到这一点,实际上元素的边框在元素外部呈现,因此没有直接的方法可以做到这一点,但是如果您想让文本垂直位于边框中间,那么您需要在标记和CSS中更改一些内容

首先,使用一个简单的
span
标记包装单词,然后在CSS中使用以下规则

还要确保使用
position:relative在下面的id上,否则它们将在野外流出

#test1 {
    height: 0px;
    border-bottom: 50px solid #648291; /*grey*/
    position: relative;
}
#test2 {
    height: 0px;
    border-top: 50px solid #FA8723; /*orange*/
    position: relative;
}
#test1 {
    height: 0px;
    border-bottom: 50px solid #648291; /*grey*/
}
#test2 {
    height: 0px;
    border-top: 50px solid #FA8723; /*orange*/
}

.v-align-bot {
    vertical-align: -50px;
}

.v-align-top {
    vertical-align: 50px;    
}
.v-align-bot span {
    position: absolute;
    top: 15px;
}

.v-align-top span {
    position: absolute;
    top: -35px;
}
#test1 {
    height: 0px;
    border-bottom: 50px solid #648291; /*grey*/
    position: relative;
}
#test2 {
    height: 0px;
    border-top: 50px solid #FA8723; /*orange*/
    position: relative;
}