标头/导航栏中的居中徽标

凯克里诺

我正在尝试创建一个网站,并从导航栏开始。我正在尝试将徽标居中,并给子/链接(?不知道它们的名称,a-tag)留出更多空间。

我尝试按照一些视频教程和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: centerheader

如今,使用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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章