简体   繁体   English

如何在导航栏上垂直居中显示这些按钮

[英]How can I get these buttons centered vertically on my navbar

I'm struggling to get these buttons on the right and the heading on the left centered vertically on my navbar. 我正在努力让这些按钮在右边,左边的标题在我的导航栏上垂直居中。 I'm not using Bootstrap. 我没有使用Bootstrap。 I've tried a number of combinations of padding and margins and can't seem to make it work. 我已经尝试了许多填充和边距的组合,似乎无法使其工作。 Can anyone help please? 有人可以帮忙吗?

HTML: HTML:

<header>
<nav>
    <h1>Jason</h1>
    <div class="navbar-box">
        <ul id="navbar-links">
            <button>
                <li><a href="#">About</a></li>
            </button>
            <button>
                <li><a href="#">Portfolio</a></li>
            </button>
            <button>
                <li><a href="#">Contact</a></li>
            </button>
        </ul>
    </div>
</nav>
</header>

CSS: CSS:

nav {
  background-color: #061839;
  color: white;
  height: auto;

}
.navbar-box {
  background-color: #061839;
  color: white;
  height: 25px;
}
h1 {
  margin-top: 5px;
  padding-top: 40px;
  padding-left: 30px;
  font-size: 40px;
}
ul {
   list-style-type: none; 
}
li a {
  display: inline;
  float:right;
}
button {
    background-color: #4D638C;
    border: none;
    color: white;
    margin-right: 20px;
    padding: 15px 32px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    float:right;
    border-radius:12px;

}

尝试添加display:inline-block和vertical-align:middle to heading(h1)和buttons容器.navbar-box

使用应该集中他们的margin auto

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM