CSS 导航栏内容缩放

CSS Navbar contents scaling

您好,我只是想知道什么是缩放导航栏以使框的大小与屏幕宽度相关的最佳方式?

只是想让它稍微响应一下。谢谢

这里是 CSS:

body {
  background-image: url("background2.jpg");
}
#navbar ul {
  padding: 5px;
  list-style-type: none;
  text-align: center;
  margin-left: 5%;
}
#navbar ul li {
  display: inline;
  float: left;
}
#navbar a:link {
  text-decoration: none;
  padding: 15px 162.5px;
  margin-left: auto;
  margin-right: auto;
  width: auto;
  color: white;
  background-color: #003333;
  font-size: 25px;
  font-family: Courier New;
}
#navbar ul li a:hover {
  color: black;
  background-color: #c2d6d6;
  text-decoration: line-through;
}
#navbar {
  background-color: #003333;
  width: 100%;
  height: 68px;
  border-radius: 15px;
}
a {
  display: block;
  width: 100px;
  background-color: #003333;
  transition-duration: 1s;
}
#navbar #currentpage a {
  color: black;
  text-decoration: line-through;
  background-color: #c2d6d6;
}

[编辑]感谢您的所有回答!

您可以尝试 CSS3 vh 和 vw 单位

详情请查看下面的 link

检查这个

css3 units

viewport-sized-typography

viewport-units-vw-vh-vmin-vmax

body {
  background-image: url("background2.jpg");
}
a {
  display: block;
  background-color: #003333;
  transition-duration: 1s;
}
#navbar {
  background-color: #003333;
  border-radius: 15px;
  overflow: hidden;
}
#navbar ul {
  list-style-type: none;
  text-align: center;
  table-layout: fixed;
  display: table;
  padding: 0;
  width: 100%;
  margin: 0;
}
#navbar ul li {
  vertical-align: middle;
  display: table-cell;
}
#navbar a {
  text-decoration: none;
  color: #fff;
  padding: 15px 10px;
  background-color: #033;
  font-size: 25px;
  font-family: Courier New;
}
#navbar ul li a:hover {
  color: black;
  background-color: #c2d6d6;
  text-decoration: line-through;
}

#navbar #currentpage a {
  color: black;
  text-decoration: line-through;
  background-color: #c2d6d6;
}
<nav id="navbar">
   <ul>
     <li><a href="#">Home</a></li>
     <li><a href="#">Biography</a></li>
     <li><a href="#">Gallery</a></li>
     <li><a href="#">Events</a></li>
  </ul>
</nav>

好吧,如果您只想缩放菜单,我会使用视口相对单位(vw 表示宽度,vh 表示高度,两者都是视口大小的百分比).

您也可以尝试使用 CSS transform: scale() function and\or zoom 属性.

请注意,两者仍处于工作草稿状态(尽管现代浏览器广泛支持)。

为了响应速度,我会发送给您阅读更多关于 @media queries 的内容。

<!DOCTYPE html>
<html>
<head>
<title>equal width</title>

<style type="text/css">
html { font: 0.75em/1.5 sans-serif; }
.tabs { margin:  0; padding: 0; list-style: none; display: table; table-layout: fixed; width: 100%; }
.tabs__item { display: table-cell; } 
.tabs__link { display: block; }
.primary-nav { text-align: center; border-radius: 4px; overflow: hidden; }
.primary-nav a { padding: 1em; background-color: #BADA55; color: #fff; font-weight: bold; text-decoration: none; }
.primary-nav a:hover { background-color: #A3C43B; }
</style>
</head>

<body>
  <ul class="tabs  primary-nav">
    <li class="tabs__item">
        <a href="#" class="tabs__link">Home</a>
    </li>
    <li class="tabs__item">
        <a href="#" class="tabs__link">About</a>
    </li>
    <li class="tabs__item">
        <a href="#" class="tabs__link">Work</a>
    </li>
    <li class="tabs__item">
        <a href="#" class="tabs__link">Contact</a>
    </li>
</ul>  
</body>
</html>