首页 > 解决方案 > 中心绝对值 UL's LI

问题描述

我试图将这些点集中在我的绝对 UL 上。在网上尝试了很多不同的答案后,我遇到了很多麻烦。

这是 CSS(.new-dots 是 UL):

.photos {
    .new-dots {
      width: 100%;
      position: absolute;
      top: 0;
      text-align: center;

      li {
        display: inline;
        color: rgba(202, 202, 202, 0.78);
        margin-right: 5px;

        button {
          background: rgba(202, 202, 202, 0.75);
          border-width: 0;
          width: 16px;
          height: 16px;
          border-radius: 8px;
          color: transparent;
        }

        button:focus {
          outline: none;
        }
      }

      .slick-active {
        button {
          background: #FFF !important;
        }
      }
    }

    .photo {
      height: 100vw;
    }
  }

标签: htmlcsssass

解决方案


  • 从更改display: inline-block;为。lidisplay: inline;
  • 默认情况下ul有自己的paddingand margin,所以你需要删除它。在您的情况下,您必须设置padding-left: 0.

  • 此外,您还可以width: 100%uland set 中删除leftrightto0以使其占据其父级的全宽。

.photos .new-dots {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding-left: 0;
}
.photos .new-dots li {
  display: inline-block;
  color: rgba(202, 202, 202, 0.78);
  margin-right: 5px;
}
.photos .new-dots li button {
  background: rgba(202, 202, 202, 0.75);
  border-width: 0;
  width: 16px;
  height: 16px;
  border-radius: 8px;
  color: transparent;
}
.photos .new-dots li button:focus {
  outline: none;
}
.photos .new-dots .slick-active button {
  background: #fff !important;
}
.photos .photo {
  height: 100vw;
}
<div class="photos">
  <ul class="new-dots">
    <li><button>123</button></li>
    <li><button>456</button></li>
    <li><button>789</button></li>
  </ul>
</div>

工作笔在这里


推荐阅读