物品的导航和文本

时间:2019-02-23 20:06:44

标签: html css image navigation navbar

我目前正在尝试创建一个导航栏,在

  • 标记的顶部有一个中等大小的图像,下面带有文本(类似于css-tricks)。 我已经尝试过背景图片以及li标签本身中的img,但仍然没有任何乐趣。

    我的主要目标是使用户可以单击图标和/或文本,并且仍将其定向到正确的页面。

    如果您还有其他问题,我们非常乐意为您提供帮助。

    nav#navBar img {
        height: 80px;
        margin-left: 80px;
    }
    
    nav#navBar {
        background-color: white;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 80px;
        display: flex;
        align-items: center;
        box-shadow: 0 0 25px 0 black;
        font-family: 'Nunito Sans', sans-serif;
        font-variant: small-caps;
        font-weight: 600;
      }
    
    nav#navBar * {
        display: inline;
        padding: 15px;
    }
    
    nav#navBar li {padding: 30px;}
    nav#navBar li.blue:hover {border-bottom: 2px solid #33A1DE;}
    nav#navBar li.red:hover {border-bottom: 2px solid #CC3232;}
    nav#navBar li.green:hover {border-bottom: 2px solid #28AE7B;}
    nav#navBar li.purple:hover {border-bottom: 2px solid #7A378B;}
    
    nav#navBar li a {
        color: black;
        text-decoration: none;
    }
      <nav id="navBar">
        <img src="#">
        <ul>
          <li class="green"><a href="#home">ARTICLES</a></li>
          <li class="blue"><a href="#">SNIPPETS</a></li>
          <li class="red"><a href="#">MEMBERS</a></li>
          <li class="purple"><a href="#">CONTACT</a></li>
        </ul>
      </nav>

  • 1 个答案:

    答案 0 :(得分:0)

    您必须在li标签上放置背景图片,并使用填充将文本向下推。

    nav#navBar li.green {background:url(image.jpg) no-repeat; padding-top: 30px;}