在 div 中居中垂直列表

Center a vertical list inside a div

我正在努力解决可能很容易解决的问题。我在响应式 div 中有一个无序列表和 3 个项目。

我已经设法将它水平居中,但垂直是我挣扎的地方。

<div class="left">  
    <div class="boxtext">
        <div class="insidetext"> 
            <ul>
                <li>WATER</li>
                <li>JUICE</li>
                <li>TEA</li>
            </ul>
        </div>
    </div>
</div>

.left {
    @include aspect-ratio(16,9);
    width: 50%;
    height: 100vh;
    min-width: 300px;
    position: relative;
    background-size: cover;
    background-color:#333;
    position: relative;
}

@media (max-width:768px) {
    .left {
        width: 100%;
        height: 70vh;
    }
}

.boxtext {
    @include aspect-ratio(16,9);
    border: solid white 0.15em;
    height: 70vh;
    width: 70%;
    margin: auto;
    position: absolute;
    top: 0; 
    left: 0; 
    bottom: 0; 
    right: 0;
    text-align: center;
}

@media (max-width:768px) {
    .boxtext {
        width: 70%;
        height: 70%;
    }
}
.insidetext {
    @include aspect-ratio(16,9);
    background-color: aliceblue;
    height: 70%;
    width: 70%;
    margin: auto;
    position: absolute;
    top: 0; 
    left: 0; 
    bottom: 0; 
    right: 0;
    font-size: 9vh;
    text-align: center;
    min-height:100px;
}

.insidetext li {
    list-style-type:none;
}

.insidetext ul {
    display: table;
    margin: 0 auto;
}

.insidetext ul,li {
    list-style-type: none;
    list-style-position:inside;
    margin:0 auto;
    padding:0;
    vertical-align:middle;
}

这里有一个测试:http://jsfiddle.net/qq3LLop8/

这应该有效:

.insidetext ul {
  display: table;
  margin: 0 auto;
  position: relative;                   <-- Note these additions
  top: 50%;                             <--
  transform: translateY(-50%);          <--
}

参见示例:

https://jsfiddle.net/atasker2/jo6etx0u/

只需将 display: table; 添加到 .insidetext 并将 display: table-cell; 添加到 .insidetext ul