border影响父元素的高度-解决方案

现象:在为Menu组件添加样式时发现,当我点击某个tab时父元素的高度会撑开,原因是boder-bottom设置为2px,第一反应是将border-sizing设置为border-box,使得widthheight属性包括内容,内边距和边框,但不包括外边距。但是无效,因为我没有为父元素设置宽高。

 

1655864862453

.menu{
    display: flex;
    flex-wrap: wrap;
    padding-left: 0;
    margin-bottom: 30px;
    list-style: none;
    border-bottom: $menu-border-width solid $menu-border-color;
    box-shadow: $menu-box-shadow;
    >.menu-item {
      padding: $menu-item-padding-y $menu-item-padding-x;
      cursor: pointer;
      transition: $menu-transition;
      &:hover, &:focus {
        text-decoration: none;
      }
      &.is-disabled {
        color: $menu-item-disabled-color;
        pointer-events: none;
        cursor: default;
      }
      &.is-active, &:hover {
        color: $menu-item-active-color;
        border-bottom: $menu-item-active-border-width solid $menu-item-active-color;
      }
   }
}

解决:换一种方法解决,在menu-item添加border-bottom的样式与点击时的样式一样,但颜色设置为transparent就行!

 >.menu-item {
      padding: $menu-item-padding-y $menu-item-padding-x;
      cursor: pointer;
      transition: $menu-transition;
      border-bottom: $menu-item-active-border-width solid transparent;

      &:hover, &:focus {
        text-decoration: none;
      }
...

 

1655865242469

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值