Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在div中定位文本?_Html_Css_Text_Position - Fatal编程技术网

Html 如何在div中定位文本?

Html 如何在div中定位文本?,html,css,text,position,Html,Css,Text,Position,对于如何在div中定位文本,我有点困惑。我希望文本在div高度方面位于div的中心,因此我尝试更改顶部填充和边距以及位置,但没有任何效果。这以前对我来说很有效,所以我不知道为什么现在不起作用。 这是我的密码 <div class="foot"> <div class="menu">English</div> <div class="menu">Maths</div> <div class="menu">

对于如何在div中定位文本,我有点困惑。我希望文本在div高度方面位于div的中心,因此我尝试更改顶部填充和边距以及位置,但没有任何效果。这以前对我来说很有效,所以我不知道为什么现在不起作用。 这是我的密码

<div class="foot">
    <div class="menu">English</div>
    <div class="menu">Maths</div>
    <div class="menu">Science</div>
    <div class="menu">SAM</div>
    <div class="menu">German</div>
</div>

这应该对你有用

.menu {
    line-height: 40px; /* add this */
    padding: 0 7%; /* changed this */
}

页脚包装的高度为40px。因此,通过使用内线元素的行高40px,它将使文本位于40px的中间。

垂直填充和边距显示,在我看来,行内块显示可以:

.menu{
    width: 200px;
    display: inline;
    padding: 0 7%;
    font-size: 20px;
    position: relative;

}
.foot{
    width: 100%;
    height: 40px;
    line-height:40px;
    position: fixed;
    bottom: 0px;
    background-color: #54a992;
    border-top: solid black 1px;
    text-align: center;
    opacity: 100%;
    z-index: 2;
    left: 0px;
}
.menu{
    margin-top: 25%;  /* Adjust it as you wish */
    width: 80px;
    display: inline-block;
    font-size: 15px;
    position: relative;
}

好的,谢谢:不管有没有改变填充物,它的工作原理都是一样的
.menu{
    margin-top: 25%;  /* Adjust it as you wish */
    width: 80px;
    display: inline-block;
    font-size: 15px;
    position: relative;
}