简体   繁体   English

如何对齐我的导航栏 css

[英]How do I align my navbar css

.home {
  background: transparent;
  border: 1px solid #fff;
  border-color: #fff;
  border-radius: 10px;
  font-weight: 700;
  padding: 14px 36px;
  margin-top: 200px;
  margin-right: 5px;
}

- ——

<nav>
    <ul>
        <li class="home"><a href="#">Home</a></li>
        <li class="home"><a href="#">About</a></li>
        <li class="home"><a href="#">Projects</a></li>
    <ul>
</nav>

I provided my HTML and CSS code我提供了我的HTMLCSS代码

Website looks like: http://prntscr.com/im5t4e网站看起来像: http : //prntscr.com/im5t4e

How do I centre my 3 buttons in the middle?如何将我的 3 个按钮居中?

When you're trying to center elements inside a container, your best shot is to use Flexbox , since you can easily position items in a row or a column, change their order, among other things.当您尝试将容器内的元素居中时,最好的方法是使用Flexbox ,因为您可以轻松地将项目放置在一行或一列中、更改它们的顺序等。 In this particular case, you should try to use the justify-content property with the center value.在这种特殊情况下,您应该尝试将 justify-content 属性与中心值一起使用。 Finally, give a display: inline property to the li elements so they're shown as inline elements instead of block-type elements.最后,为li元素提供display: inline属性,以便它们显示为内联元素而不是块类型元素。

Example:例子:

CSS CSS

nav {
  display: flex;
  justify-content: center;
}

li {
  display: inline;
}

HTML HTML

<nav>
  <ul>
    <li class="home"><a href="#">Home</a></li>
    <li class="home"><a href="#">About</a></li>
    <li class="home"><a href="#">Projects</a></li>
  <ul>
</nav>

Give text-align: center;text-align: center; for ul and display: inline-block;对于uldisplay: inline-block; for li .li

ul{
    text-align:center;
}
.home {
    background: transparent;
    border: 1px solid #fff;
    border-color: #fff;
    border-radius: 10px;
    font-weight: 700;
    padding: 14px 36px;
    margin-top: 200px;
    margin-right: 5px;
    display: inline-block
}
<nav>
    <ul >
        <li class="home"><a href="#">Home</a></li>
        <li class="home"><a href="#">About</a></li>
        <li class="home"><a href="#">Projects</a></li>
    <ul>
</nav>

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

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