【问题标题】:Materialize CSS- Align navbar to the far rightMaterialize CSS - 将导航栏对齐到最右边
【发布时间】:2018-07-15 09:43:28
【问题描述】:

我正在使用物化 CSS 并创建了一个导航,但想将其向右移动一点,而不影响徽标的位置。请参阅下面的当前图片;

导航栏照片

我当前的代码:

< div class="navbar-fixed">
  <nav class="white" role="navigation" id="top-nav">
    <div class="nav-wrapper container">
      <a id = "logo-container" href="#" class="brand-logo"><img src = "img/DataNavSmaller.png" ></ a >

        < ul class="right hide-on-med-and-down">
        <li><a href = "#" class="active">Home</a></li>
        <li><a href = "#" > Who We Are</a></li>
        <li><a href = "#" > What We Do</a></li>
        <li><a href = "#" > Contact Us</a></li>
      </ul>

      <ul id = "nav-mobile" class="sidenav">
        <li><a href = "#" > Navbar Link</a></li>
      </ul>
      <a href = "#" data-target="nav-mobile" class="sidenav-trigger"><i class="material-icons">menu</i></a>
    </div>
  </nav>
</div>

CSS:

nav.brand - logo {

    margin - left: -60px;
    padding - top: 4px;
}

nav.right {

    padding - top: 10px;

}
nav ul a{

    color: black;
    font - size:20px;

}

我怎样才能实现上述目标?

【问题讨论】:

    标签: html css materialize


    【解决方案1】:

    您可以使用 CSS 属性 position: fixed; top: 10px; right: 5px; 设置导航栏的右侧。 position: fixed 使元素保持原位。 top 指定元素与top 的距离,right 指定元素与right 的距离(这些属性仅在设置display 属性时有效)。

    .navbar-fixed{
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      height: 50px;
      background-color: #BEBEBE;
    }
    .logo{
      margin: 10px 10px 10px 15px;
       background: red;
       padding: 5px;
       background: linear-gradient(red, yellow, green);
       width: 60px;
       height: 25px;
       color: white;
    }
    .navbar-right{
      position: fixed;
      top: 10px;
      right: 5px;/*pixels away from the right of the navbar*/
    }
    
    .title{
      display: inline-block;
      margin: 5px;
    }
    <div class="navbar-fixed">
    <div class="logo">
    <!--<img src="something.png" alt="img"/>-->
    DataNav
    </div>
    <div class="navbar-right">
    <div class="title">
    Home
    </div>
    <div class="title">
    Who we are
    </div>
    <div class="title">
    What we do
    </div>
    <div class="title">
    Contact us
    </div>
    </div>
    </div>

    【讨论】:

    • 非常感谢,position:fixed 改变了问题。默认位置是绝对的。
    • @Couch 没问题。
    【解决方案2】:

    怎么样

    导航 .right { 浮动:对; }

    【讨论】:

    • 默认属性为float:right,将位置从绝对位置更改为固定位置可以解决问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多