html - 绝对中心 UL's LI

标签 html css sass

我试图将这些点集中在我的绝对 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;
    }
  }

最佳答案

将其添加到元素中,它将使子元素在父元素中居中。

代码示例

body {
position: relative;
height: 100vh;
}

.new-dots {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  
}
<div class="new-dots">Test Content</div>

关于html - 绝对中心 UL's LI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50299662/

相关文章:

javascript - AngularJS 默认下拉选择不工作

css - 使用 CSS 进行布局,清除 float 以在下一行开始 ??需要创建一个2列5行的布局

html - Div 高度为零,而它(应该)包含(多个)元素

javascript - 使用 className 样式化 react-toolbox 元素

css - 不同尺寸的流体宽度元素的正确纵横比

css - 为什么我的 <ol> 不显示元素编号?

html - 有没有一种有效的方法可以自动显示网页的所有 HTML 颜色?

css - PDF 到 HTML 转换

css - 字符串中的 SASS 变量

java - JTextPane,文本/html 内容 : nested HTML element do not inherit font size?