【发布时间】:2018-01-28 16:39:30
【问题描述】:
body {
margin: 0;
}
.header {
width: 80%;
height: 20%;
margin-left: 10%;
position: fixed;
top: 0;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
background-color: green;
}
.image {
width: 20%;
height: 100%;
float: left;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
}
.navigation {
width: 79%;
height: 100%;
float: right;
text-align: right;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
}
ul {
height: 100%;
font-size: 0;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
background-color: yellow;
}
li {
height: 100%;
font-size: initial;
display: inline-block;
box-sizing: border-box;
border-style: solid;
border-width: 1px;
background-color: blue;
}
<div class="header">
<div class="image">
Image
</div>
<nav class="navigation">
<ul>
<li> 1.0 Main Menu </li>
<li> 2.0 Main Menu </li>
<li> 3.0 Main Menu </li>
</ul>
</nav>
</div>
使用上面的代码,我创建了一个包含<image> 和<navigation> 的<header>。到目前为止,这一切都很好。
现在我希望<li> 元素内的文本 出现在中心。因此,我尝试使用li CSS 中的属性text-align: center;,但没有成功。
为了使<li> 元素居中 中的文本,我必须在我的代码中进行哪些更改?
你也可以在这里找到我的代码:https://jsfiddle.net/5jv8m5xf/39/
【问题讨论】:
-
您是否尝试将“text-align: center”添加到您的“
- ”元素中?
-
是的,但它会将
- 元素置于中心。不是
- 元素中的文本。
-
@Michi 你想让文本垂直对齐吗?
-
我已经尝试使用
text-aling:center及其作品。我无法看到效果,因为- 宽度太小了,如果你增加它也许你会看到。
标签: html css vertical-alignment centering