.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 40px;
  padding: 0 10px;
}

.button {
  height: 100%;
  line-height: 40px;
  padding: 0 10px;
}

.left {
  margin-right: 10px;
}

.right {
  margin-left: 10px;
}

.title {
  width: 100px;
  text-align: center;
}

解释:

  1. 将导航栏设置为 flex 布局,使左右按钮和标题可以分别靠左、右、中间对齐;
  2. 使用 justify-content: space-between; 将左右按钮与标题分别靠左、右两端对齐;
  3. 使用 align-items: center; 将左右按钮和标题垂直居中对齐;
  4. 左右按钮设置 margin-leftmargin-right 为 10px,使其距离边框有 10px 的间距;
  5. 标题设置宽度为 100px,使用 text-align: center; 使其居中对齐。
Vue 无需定位实现 400px 导航栏,按钮距离边框 10px,标题居中

原文地址: http://www.cveoy.top/t/topic/n30k 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录