导航栏上徽标旁边的定位链接

时间:2015-04-13 14:22:35

标签: html css3 nav

基本上我正在做的是尝试将导航链接置于导航栏中间的中心位置。我读了一下漂浮物:左;可能会影响它旁边的div的定位。所以我的问题是有任何解决方案可以在导航栏中间获取导航链接吗?

@import url(http://fonts.googleapis.com/css?family=Oswald);
 * {
  margin: 0;
  padding: 0;
}
/* Navigation Styles */

.nav {
  height: 80px;
  background-color: #ffffff;
  border-bottom: 1px solid #aeaeae;
  position: fixed;
  width: 100%;
}
.logo h2 {
  float: left;
  padding-left: 70px;
}
.logo a {
  text-decoration: none;
  color: #9595a2;
  font-size: 50px;
  font-family: 'Oswald', sans-serif;
  -webkit-transition-property: color, text;
  -webkit-transition-duration: .1s, .1s;
  -webkit-transition-timing-function: linear, ease-in;
  -moz-transition-property: color, text;
  -moz-transition-duration: 1s;
  -moz-transition-timing-function: linear, ease-in;
  -o-transition-property: color, text;
  -o-transition-duration: 1s;
  -o-transition-timing-function: linear, ease-in;
}
.nav .logo a:hover {
  color: red;
}
.nav-links {
  float: right;
}
.nav-links ul {} .nav-links li {
  display: inline;
  list-style-type: none;
}
.nav-links a {
  padding-top: 30px;
  padding-right: 40px;
  text-decoration: none;
  font-family: 'Oswald', sans-serif;
  color: #9595a2;
  font-size: 20px;
}
/* About Styles */

.about {
  height: 880px;
  background-color: #dddddd;
  -moz-box-shadow: inset 0 8px 8px -8px #193047, inset 0 -8px 8px -8px #193047;
  -webkit-box-shadow: inset 0 8px 8px -8px #193047, inset 0 -8px 8px -8px #193047;
  box-shadow: inset 0 8px 8px -8px #193047, inset 0 -8px 8px -8px #193047;
}
.about h2 {
  font-size: 50px;
  padding-top: 105px;
  text-align: center;
  color: red;
  font-family: 'Oswald', sans-serif;
}
<html lang="en">

<head>
  <title>Moises Cortez | Graphic Designer</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" href="css/style.css" />
</head>

<body>
  <div id="page-container">
    <div class="nav">
      <div class="logo">
        <h2><a href="#">Moises</a></h2>
      </div>
      <div>
      </div>
      <div class="nav-links">
        <li><a href="#">About</a>
        </li>
        <li><a href="#">Portfolio</a>
        </li>
        <li><a href="#">Skills</a>
        </li>
        <li><a href="#">Contact</a>
        </li>
      </div>
    </div>
    <div class="about">
      <h2>About</h2>
    </div>
  </div>
</body>

</html>

2 个答案:

答案 0 :(得分:1)

HTML中的锚标记是内联元素。能够给他们边距或填充。您必须显示块或内联块以使锚点成为块级元素。

<强> CSS

.nav-links a{
  display: inline-block;
}

将CSS行添加到现有选择器中。

答案 1 :(得分:0)

根据要求,您可以将 display:table; display:table-cell 用于菜单中的children元素。然后将vertical-align:middle添加到每个table-cell元素。这种方法可以避免对边距和填充进行任何计算,并且可以很容易地对每个元素进行垂直对齐。

  1. 我建议你在.nav中创建另一个包装器,调用 .nav-wrapper

  2. .nav-wrapper设置为display:table;,高度和宽度均为100%。

  3. 将.nav-link和.logo设置为display:table-cell; vertical-align:middle;,以便垂直对齐。

  4. 从链接中删除填充顶部并将每个链接显示为display:inline-block;

  5. 检查演示

    @import url(http://fonts.googleapis.com/css?family=Oswald);
     * {
      margin: 0;
      padding: 0;
    }
    /* Navigation Styles */
    
    .nav {
      height: 80px;
      background-color: #ffffff;
      border-bottom: 1px solid #aeaeae;
      position: fixed;
      width: 100%;
    }
    .nav-wrapper{
      display:table;
      height:100%;
      width:100%;
    }
    .logo{
      display:table-cell;
      vertical-align:middle;
    }
    
    .logo h2 {
      float: left;
      padding-left: 70px;
    }
    .logo a {
      text-decoration: none;
      color: #9595a2;
      font-size: 50px;
      font-family: 'Oswald', sans-serif;
      -webkit-transition-property: color, text;
      -webkit-transition-duration: .1s, .1s;
      -webkit-transition-timing-function: linear, ease-in;
      -moz-transition-property: color, text;
      -moz-transition-duration: 1s;
      -moz-transition-timing-function: linear, ease-in;
      -o-transition-property: color, text;
      -o-transition-duration: 1s;
      -o-transition-timing-function: linear, ease-in;
    }
    .nav .logo a:hover {
      color: red;
    }
    .nav-links {
      display:table-cell;
      vertical-align:middle;
      text-align:right;
    }
    .nav-links li {
      display: inline-block;
      list-style-type: none;
    }
    .nav-links a {
      padding-right: 40px;
      text-decoration: none;
      font-family: 'Oswald', sans-serif;
      color: #9595a2;
      font-size: 20px;
    }
    /* About Styles */
    
    .about {
      height: 880px;
      background-color: #dddddd;
      -moz-box-shadow: inset 0 8px 8px -8px #193047, inset 0 -8px 8px -8px #193047;
      -webkit-box-shadow: inset 0 8px 8px -8px #193047, inset 0 -8px 8px -8px #193047;
      box-shadow: inset 0 8px 8px -8px #193047, inset 0 -8px 8px -8px #193047;
    }
    .about h2 {
      font-size: 50px;
      padding-top: 105px;
      text-align: center;
      color: red;
      font-family: 'Oswald', sans-serif;
    }
    <html lang="en">
    
    <head>
      <title>Moises Cortez | Graphic Designer</title>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" type="text/css" href="css/style.css" />
    </head>
    
    <body>
      <div id="page-container">
        <div class="nav">
          <div class="nav-wrapper">
          <div class="logo">
            <h2><a href="#">Moises</a></h2>
          </div>
          <div class="nav-links">
            <li><a href="#">About</a>
            </li>
            <li><a href="#">Portfolio</a>
            </li>
            <li><a href="#">Skills</a>
            </li>
            <li><a href="#">Contact</a>
            </li>
          </div>
          </div>  
        </div>
        <div class="about">
          <h2>About</h2>
        </div>
      </div>
    </body>
    
    </html>