gpt4 book ai didi

html - 导航标题 html css 中的居中元素

转载 作者:行者123 更新时间:2023-11-28 04:01:47 25 4
gpt4 key购买 nike

我制作了一个导航标题(i.d.k. 你怎么调用它),我想要一些文本在它的中间。

它基本上是一个黑色的栏,右边有一些导航按钮(例如主页、关于我们、信息、图库...),左边有一个 Logo ,现在我想在该栏的中间放置一些文本。我无法让它工作。

这是我目前的代码。

/* Global settings */

* {
font-family: Roboto;
padding: 0;
margin: 0;
}

a {
text-decoration: none;
}


/* Header settings */

.header {
height: 50px;
width: 100%;
background-color: #212121;
position: fixed;
text-align: center;
}

.header ul {
height: 100%;
float: right;
position: relative;
right: 50px;
}

.header li {
display: inline-block;
height: 100%;
width: 75px;
text-align: center;
}

.header li:hover {
background-color: #616161;
}

.header a {
display: block;
color: #FAFAFA;
height: 100%;
line-height: 50px;
border: 1px solid orange;
}

.header img {
height: 100%;
color: #FAFAFA;
float: left;
}

.header h1 {
color: #FAFAFA;
Line-height: 50px;
display: inline-block;
}
<body>
<div class="header">
<h1>The text I want to be centered</h1>
<ul>
<li><a href="">Home</a></li>
<li><a href="">Info</a></li>
<li><a href="">Contact</a></li>
<li><a href="">About</a></li>
</ul>
<img src="" alt="Logo" />
</div>
</body>

最佳答案

你可以试试这个:
HTML

<body>
<div class="header">
<img src="" alt="Logo" />
<h1>The text I want to be centered</h1>
<ul>
<li><a href="">Home</a></li>
<li><a href="">Info</a></li>
<li><a href="">Contact</a></li>
<li><a href="">About</a></li>
</ul>
</div>
</body>

CSS

* {
font-family: Roboto;
padding: 0;
margin: 0;
}

a {
text-decoration: none;
}

/* Header settings */
.header {
width: 100%;
background-color: #212121;
position: fixed;
text-align: center;
display:flex;
justify-content:space-between;
padding:0 10px;
box-sizing: border-box;
}

.header ul {
height: 100%;
position: relative;
}

.header li {
display: inline-block;
height: 100%;
width: 75px;
text-align: center;
}

.header li:hover {
background-color: #616161;
}

.header a {
display: block;
color: #FAFAFA;
height: 100%;
line-height: 50px;
border: 1px solid orange;
}

.header img {
height: 100%;
color: #FAFAFA;
}

.header h1 {
color: #FAFAFA;
line-height: 50px;
display: inline-block;
}

上面的内容是将文本与 Logo 和菜单等距放置。因此,文本不会精确居中,但可能看起来更“正确”。

关于html - 导航标题 html css 中的居中元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43171642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com