html - 边框图像出现在所有菜单项之间,但不出现在最后一个菜单项之间

标签 html css border

我正在使用边框图像来分隔导航栏中的菜单项。该图像出现在所有元素的顶部,但我也希望它出现在最后一个元素的底部。我尝试使用 last-child 并使用 center bottom 但随后它从最后一个元素的顶部消失并出现在底部。请检查这张图片 - i.ibb.co/hBS62fN/Screenshot-1.jpg。这是我的代码:

我只希望边框图像出现在我的 navbar 的所有四个元素的顶部和底部。

这是我迄今为止尝试过的。此代码从联系人顶部删除边框并将其放在底部。

    .main-nav {
      width: 100%;
      height: 200px;
    }

    .nav-content {
      width: 100%;
      height: 100%;
    }

    .main-nav ul {
      list-style: none;
      display: block;
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100%;
    }

    .main-nav ul li {
      width: 100%;
      height: 45px;
      background-image: url(../images/borderimage.png);
      background-repeat: no-repeat;
      background-position: center top;
      margin: 0;
      padding: 0;
    }

    .main-nav ul li a {
      font-weight: normal;
      font-size: 15px;
      color: #AA9776;
      text-decoration: none;
      /*    background-image: url(../images/menucizgi.png);
        background-repeat: no-repeat;
        background-position: center top;*/
      float: left;
      height: 23px;
      width: 157px;
      text-align: left;
      text-shadow: 2px 2px 10px #000;
      padding: 8px 0 10px 45px;
      margin: 2px 0;
    }

    .main-nav ul li a.active {
      color: #AA9776;
      /*background-image: url(../images/menuover.jpg);
        background-repeat: no-repeat;
        background-position: center top;*/
      background: rgba(0, 0, 0, 0.7);
      text-shadow: 0 1px 1px #000;
      -webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.9), 0 1px 0 #000;
      -moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.9), 0 1px 0 #000;
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.9), 0 1px 0 #000;
      -webkit-transition: all 1s ease;
      -moz-transition: all 1s ease;
      -o-transition: all 1s ease;
      -ms-transition: all 1s ease;
      transition: 1s ease;
    }

    .main-nav ul li a:hover {
      color: #AA9776;
      /*background-image: url(../images/menuover.jpg);
        background-repeat: no-repeat;
        background-position: center top;*/
      background: rgba(0, 0, 0, 0.7);
      text-shadow: 0 1px 1px #000;
      -webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.9), 0 1px 0 #000;
      -moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.9), 0 1px 0 #000;
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.9), 0 1px 0 #000;
      -webkit-transition: all 1s ease;
      -moz-transition: all 1s ease;
      -o-transition: all 1s ease;
      -ms-transition: all 1s ease;
      transition: 1s ease;
    }
  .main-nav ul li:last-child {
      background-image: url(../images/borderimage.png);
      background-repeat: no-repeat;
      background-position: center bottom;
    }
    <div class="main-nav">
      <div class="nav-content">
        <ul>
          <li><a href="#about" class="active">About</a></li>
          <li><a href="#leather">Leather</a></li>
          <li><a href="#leather-goods">Leather Goods</a></li>
          <li><a href="#contact">Contact</a></li>
        </ul>
      </div>
    </div>

最佳答案

两个可能有效的选项:

尝试将最后一个 child 修改为:

.main-nav ul li:last-child {
      background: url(../images/borderimage.png) center bottom no-repeat, 
                  url(../images/borderimage.png) center top no-repeat,
}

或将其添加到您现有的 CSS 中:

.main-nav ul li:last-child:before {
      background-image: url(../images/borderimage.png);
      background-repeat: no-repeat;
      background-position: center top;
}

如果不在演示中对其进行测试,则不确定它是否会起作用。

关于html - 边框图像出现在所有菜单项之间,但不出现在最后一个菜单项之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57795137/

相关文章:

html - 在无法修改 HTML 的情况下,为 CMS 生成的 HTML 编写 CSS 的最佳策略是什么?

css - 带有 CSS 三 Angular 形的标签边框

javascript - 为什么 document.getElementById 返回空值?

javascript - 通过用鼠标旋转一个圆来平移平面

jquery - 使用 jQuery 在 ID 具有类时显示内容

css - 如何禁用 ZK 的所有 css/主题?

html - 内联导航

html - 将 "Contact Box"居中并使其响应

css - IE 6.0 需要一个非常细的边框

java - 如何在 LinearLayout 周围的边框中实现间隙?