Add empty space between div's content and bottom border

后端 未结 4 715
孤城傲影
孤城傲影 2021-01-17 11:52

I am attempting to add a bottom border to a div for the purpose of a navigation bar. The effect I am trying to achieve:

4条回答
  •  北海茫月
    2021-01-17 12:12

    As it currently stands you can't do this. You can't add a gap between an element and its own border. You can, however, add the border to its parent element (the div.item element in this case), then add padding-bottom to that same element to separate it from the a element:

    $("a").click(function() {
      
      $(".current").removeClass("current");
      
      $(this).parent().addClass("current");
      
      });
    .container {
    }
    
    .container .item {
      float: left;
      list-style-type: none;
      margin: 0 1px;
    }
    
      .container .item a {
        color: black;
        text-decoration: none;
        background-color: green;
        width: 50px;
        font-size: 13px;
        text-align: center;
        font-weight: bold;
        display: table-cell;
        vertical-align: middle;
        height: 40px; 
      }
    
        .container .item.current {
          border-bottom: 2px solid red;  
          padding-bottom: 4px;
        }
    
    
    

    Note that I've also modified your JavaScript to add this .current class to the li element and not the clicked a element.

提交回复
热议问题