首页 > 解决方案 > 中心导航栏链接

问题描述

我似乎无法将导航栏按钮居中。有没有办法在css文件中做到这一点?我尝试过居中,但没有奏效。

HTML

<div class="navbar">
  <a href="#home">Home</a>
  <a href="#news">News</a>
  <a href="#contact">Contact</a>
</div>

CSS

.navbar {
  overflow: hidden;
  background-color: #333;
  position: fixed; /* Set the navbar to fixed position */
  top: 0; /* Position the navbar at the top of the page */
  width: 1300px; /* Full width */
  z-index: 99999;
  text-align: center;
}

/* Links inside the navbar */
.navbar a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

/* Change background on mouse-over */
.navbar a:hover {
  background: #ddd;
  color: black;
}

标签: htmlcssweb

解决方案


/* Links inside the navbar */
.navbar a {
 display:inline-block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

我已经修改了“.navbar a”的样式。希望它对你有用。


推荐阅读