@QnaTwitt

Как прижать бордер к grid элементам?

Как прижать крассный бордер к grid элементам, сейчас он занимает всю ширину контейнера в которой он находится...

codepen

<section class="box-container --small">
  <ul>
    <li><a><span>text</span></a></li>
    <li><a><span>text</span></a></li>
    <li><a><span>text</span></a></li>
    <li><a><span>text</span></a></li>
    <li><a><span>text</span></a></li>
    <li><a><span>text</span></a></li>
    <li><a><span>text</span></a></li>
    <li><a><span>text</span></a></li>
    <li><a><span>text</span></a></li>
  </ul>
</section>


css
*,
*::before,
*::after {
  box-sizing: border-box;
  outline: 0;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

a {
  text-decoration: none;
  cursor: pointer;
  color: inherit;
}

ul,
li {
  list-style: none;
}

button,
input {
  background: none;
  border: none;
}

[class*="-container"],
.container {
  width: 100%;
  padding: 0 15px;
  margin: 0 auto;

  @media (min-width: 320px) {
    max-width: 373px;
  }

  @media (min-width: 1024px) {
    max-width: 960px;
  }

  @media (min-width: 1280px) {
    max-width: 1200px;
  }

  @media (min-width: 1920px) {
    max-width: 1824px;
  }

  &.--small {
    @media (min-width: 320px) {
      max-width: 373px;
    }

    @media (min-width: 1024px) {
      max-width: 640px;
    }

    @media (min-width: 1280px) {
      max-width: 800px;
    }

    @media (min-width: 1980px) {
      max-width: 1215px;
    }
  }
}

.box-container {
  ul {
    position: relative;
    display: grid;
    justify-content: center;
    overflow: hidden;

    &::before {
      position: absolute;
      width: 100%;
      height: 100%;
      content: "";
      border: 2px solid red;
    }
  }

  li {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 1;
    border-bottom: 2px solid #f9f9f9;
    transition: background-color 0.2s ease-in-out;

    &::before {
      position: absolute;
      top: 50%;
      bottom: 50%;
      left: -3px;
      width: 1px;
      height: 4px;
      content: "";
      background-color: black;
      transform: translateY(-50%);
    }

    a {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;

      span {
        position: relative;
        display: block;
        max-width: 100px;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
        padding-top: 26px;
        font-size: 12px;
        line-height: 22px;
        text-align: center;
        transition: color 0.2s ease-in-out;

        &::before {
          position: absolute;
          top: 0;
          right: 50%;
          left: 50%;
          content: "";
          width: 14px;
          height: 14px;
          border: 1px solid black;
          border-radius: 100%;
          transform: translateX(-50%);
          transition: border-color 0.2s ease-in-out;
        }
      }
    }

    &:hover {
      background-color: green;

      &::before {
        background-color: transparent;
      }

      a span {
        color: #fff;

        &::before {
          border-color: #fff;
        }
      }
    }
  }

  li:hover + li::before {
    background-color: transparent;
  }

  @media (min-width: 320px) {
    margin-top: 96px;

    ul {
      margin: 48px auto 0;
      grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
      grid-auto-rows: minmax(variables170px, 1fr);
    }
  }

  @media (max-width: 1024px) {
    margin-top: 120px;

    ul {
      width: auto;
      margin-top: 48px;
      grid-template-columns: repeat(auto-fit, minmax(152px, 152px));
      grid-auto-rows: minmax(158px, 158px);
    }
  }

  @media (max-width: 1280px) {
    ul {
      grid-template-columns: repeat(auto-fit, minmax(192px, 192px));
      grid-auto-rows: minmax(192px, 192px);
      margin-top: 64px;
    }

    li a span {
      padding-top: 32px;
      font-size: 13px;
      line-height: 23px;

      &::before {
        width: 16px;
        height: 16px;
      }
    }
  }

  @media (max-width: 1920px) {
    margin-top: 130px;

    ul {
      grid-template-columns: repeat(auto-fit, minmax(296px, 296px));
      grid-auto-rows: minmax(296px, 296px);
      margin-top: 96px;
    }

    li a span {
      padding-top: 48px;
      font-size: 16px;
      line-height: 29px;

      &::before {
        width: 24px;
        height: 24px;
      }
    }
  }
}


Нужно что бы бордер был прижат к grid элементам, что бы не было этого пространства
638f47cfc175d471797061.jpeg638f47d130212174895178.jpeg
  • Вопрос задан
  • 90 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы