html - 在标题/导航栏中居中徽标
问题描述
我正在尝试创建一个站点并从导航栏开始。我正在尝试将徽标居中并给 subs/links(?不知道它们叫什么,a-tags)更多的空间。
我尝试遵循一些视频教程和 Stackoverflow 答案,但它们导致左侧 3 个链接更向下,而右侧 3 个链接高于其他所有链接,并导致整体标题大小几乎翻了一番。如果有人可以帮助我,我将不胜感激!:) 可能有一些不需要的垃圾代码,或者总体上是一种不好的做法,但如果不清楚我是网页设计的初学者:p
body {
margin: 0;
font-family: 'Open Sans', sans-serif;
}
.header {
overflow: hidden;
background-color: #262e28;
padding: 10px 10px;
box-shadow: 0px 2px 8px #888888;
}
.header a {
color: white;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 14px;
line-height: 25px;
border-radius: 4px;
}
.header a.logo {
font-size: 25px;
color: white;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.header a:hover {
color: #aeaeae;
}
.header a.active {
color: #aeaeae;
}
.header-right {
float: right;
}
.header-left {
float: left;
}
@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}
.header-right {
float: none;
}
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="assets/style.css">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap" rel="stylesheet"></head>
<body>
<div class="header">
<div class="header-right">
<a href="#"><b>1</b></a>
<a href="#"><b>2</b></a>
<a href="#"><b>3</b></a>
</div>
<a href="#" class="logo">LOGO</a>
<div class="header-left">
<a href="#"><b>4</b></a>
<a href="#"><b>5</b></a>
<a href="#"><b>6</b></a>
</div>
</div>
</body>
</html>
解决方案
您可以在课堂上使用display:flex
属性。align-items: center
header
如今,使用flex属性是一种推荐的方式,因为它在现代浏览器上的响应速度非常快
将此代码添加到您的标头类中
.header {
overflow: hidden;
background-color: #262e28;
padding: 10px 10px;
box-shadow: 0px 2px 8px #888888;
display: flex;
align-items: center;
flex-direction: row-reverse;
}
现场工作示例:
body {
margin: 0;
font-family: 'Open Sans', sans-serif;
}
.header {
overflow: hidden;
background-color: #262e28;
padding: 10px 10px;
box-shadow: 0px 2px 8px #888888;
display: flex;
align-items: center;
flex-direction: row-reverse;
}
.header a {
color: white;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 14px;
line-height: 25px;
border-radius: 4px;
}
.header a.logo {
font-size: 25px;
color: white;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.header a:hover {
color: #aeaeae;
}
.header a.active {
color: #aeaeae;
}
.header-right {
float: right;
}
.header-left {
float: left;
}
@media screen and (max-width: 500px) {
.header a {
float: none;
display: block;
text-align: left;
}
.header-right {
float: none;
}
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="assets/style.css">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap" rel="stylesheet">
</head>
<body>
<div class="header">
<div class="header-right">
<a href="#"><b>1</b></a>
<a href="#"><b>2</b></a>
<a href="#"><b>3</b></a>
</div>
<a href="#" class="logo">LOGO</a>
<div class="header-left">
<a href="#"><b>4</b></a>
<a href="#"><b>5</b></a>
<a href="#"><b>6</b></a>
</div>
</div>
</body>
</html>
推荐阅读
- windows - 如何正确解密帐户凭据并将其传递给 Add-LocalGroupMember 命令
- mysql - 将总和转换为百分比
- python - 具有大量点和一个约束的路由问题
- python - 我无法弄清楚如何在 scrapinghub 部署中使用 csv 文件进行列表理解
- logging - Fortify SCA 扫描在读取环境变量时报告日志伪造问题
- debugging - UnicodeString::Length() 干扰调试器显示
- javascript - Vue中使用/deep/bug
- r - 将文本转换为数字?
- azure - Azure Site Recovery 保证 Azure 到 Azure 故障转移的恢复时间目标为两小时。对于任何类型的工作负载?
- jquery - 使用不带特殊字符 + 验证格式的日期输入创建一个 from