Html 为什么我的跨度不在主容器的中间 我试图在红屏中间显示预订,但失败了,主容器必须是“代码>显示:块属性,但是我可以对子div和跨度进行更改,我能够以编程方式使用“相对位置”设置页边距顶部,但这会导致一些严重问题,因此我无法在此处使用页边距顶部,我更喜欢使用“垂直对齐:中间”和“文本对齐:中间”设置

Html 为什么我的跨度不在主容器的中间 我试图在红屏中间显示预订,但失败了,主容器必须是“代码>显示:块属性,但是我可以对子div和跨度进行更改,我能够以编程方式使用“相对位置”设置页边距顶部,但这会导致一些严重问题,因此我无法在此处使用页边距顶部,我更喜欢使用“垂直对齐:中间”和“文本对齐:中间”设置,html,css,Html,Css,HTML <div class="tabs-bottom"> <div id="tab-1"> <span>Booking</span> </div> </div> 您可以使用绝对定位或以下代码 .element { position: relative; top: 50%; transform: translateY(-50%); } 您可以使用绝对定位或下面的代码 .element {

HTML

<div class="tabs-bottom">
    <div id="tab-1"> <span>Booking</span>

    </div>
</div>

您可以使用绝对定位或以下代码

.element {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

您可以使用绝对定位或下面的代码

.element {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

最简单的解决方案是将选项卡显示更改为
block

#tab-1 {
    display: block;
    text-align: center;
    vertical-align: middle;
}

最简单的解决方案是将选项卡显示更改为
block

#tab-1 {
    display: block;
    text-align: center;
    vertical-align: middle;
}
CSS

.tabs-bottom {     // this can't change
    display:block;
    width: 100%;
    height: 255px;
    background:red;
}
#tab-1 {
    display: inline-block;
    text-align: center;
    vertical-align: middle;
}
既然你说你可以改变child
display
属性,我已经对child div的CSS做了一些调整

CSS

.tabs-bottom {     // this can't change
    display:block;
    width: 100%;
    height: 255px;
    background:red;
}
#tab-1 {
    display: inline-block;
    text-align: center;
    vertical-align: middle;
}
既然你说你可以改变child
display
属性,我已经对child div的CSS做了一些调整


垂直对齐:中间对齐仅适用于父级上设置的
行高
属性。所以只需将
高度
更改为
行高度

.tabs-bottom {
    display:block;
    width: 100%;
    line-height: 255px;
    background:red;
    text-align: center;
}
#tab-1 {
    display: inline-block;
    vertical-align: middle;
}

垂直对齐:中间对齐仅适用于父级上设置的
行高
属性。所以只需将
高度
更改为
行高度

.tabs-bottom {
    display:block;
    width: 100%;
    line-height: 255px;
    background:red;
    text-align: center;
}
#tab-1 {
    display: inline-block;
    vertical-align: middle;
}

您需要在
#tab-1
css中进行两项更改:

1。)使用
线条高度
使垂直居中
2。)更改
显示:内联块至<代码>显示:块用于水平中间

例如:

#tab-1 {
    display: block;
    line-height: 255px;
    text-align: center;
   }

检查更新的

您需要在
#tab-1
css中进行两项更改:

1。)使用
线条高度
使垂直居中
2。)更改
显示:内联块至<代码>显示:块用于水平中间

例如:

#tab-1 {
    display: block;
    line-height: 255px;
    text-align: center;
   }

查看更新的

我希望这将对您有所帮助

试试看

.tabs-bottom {
    display:block;
    width: 100%;
    height: 255px;
    background:red;
    text-align: center;
    position: relative;
}
#tab-1 {
    display: inline-block;
    text-align: center;
    vertical-align: middle;
    position: absolute;
    top: 50%;
    margin-top: -8.5px
}

我希望这对你有帮助

试试看

.tabs-bottom {
    display:block;
    width: 100%;
    height: 255px;
    background:red;
    text-align: center;
    position: relative;
}
#tab-1 {
    display: inline-block;
    text-align: center;
    vertical-align: middle;
    position: absolute;
    top: 50%;
    margin-top: -8.5px
}

可能只是删除
display:inline块

.tabs-bottom {
display:block;
width: 100%;
height: 255px;
background:red;
}
#tab-1 {
text-align: center;
vertical-align: middle;
}

可能只是删除
显示:内联块

.tabs-bottom {
display:block;
width: 100%;
height: 255px;
background:red;
}
#tab-1 {
text-align: center;
vertical-align: middle;
}

尝试使用CSS定位


尝试使用CSS定位

.main div{高度:300px;背景:红色}
.垂直中{
位置:相对位置;
最高:50%;
转换:透视(1px)translateY(-50%);
文本对齐:居中;
}

垂直中间文本
.main div{高度:300px;背景:红色}
.垂直中{
位置:相对位置;
最高:50%;
转换:透视(1px)translateY(-50%);
文本对齐:居中;
}

垂直中间文本