0

我有一个 JS MixItUp,我在文本框中有它,但我似乎无法让它在一个框中获得多行,垂直对齐,并留在元素内。

要垂直对齐,我需要设置行高并将垂直对齐设置为中间。

我将行高设置为框的大小(45px)。

在这个CodePen中,您可以在底部的方框中看到问题 - 字词直接开箱即用。

.courses span {
    border: 1px solid white;
    color: black;
    display: grid;
    font-size: 11px;
    height: 45px;
    background: #ffffff;
    border: 2px solid #505050;
    line-height: 45px;
    vertical-align: middle;
    margin: 4px 0;
    -webkit-transition: all .4s ease;
            transition: all .4s ease;
}

我还尝试遵循垂直对齐示例 CodePen,但单行将位于框的顶部。

4

2 回答 2

1

css 代码的一些变化。

试试这个更新的codepen:- https://codepen.io/bhuwanb9/pen/zwMJWj

.courses li {
    text-align: center;
    font-size: 14px;
    width: 19%;
    margin: 0.5%;
    background: #ffffff;
    border: 2px solid #505050;
    position:relative;
    height: 65px;
    box-sizing:border-box;
 }

 .courses span {
    color: black;
    font-size: 11px;
    line-height: normal;
    position:absolute;
    -webkit-transition: all .4s ease;
    transition: all .4s ease;
    transform: translateY(-50%);
    top:50%;
 }
于 2017-05-21T17:44:40.047 回答
0

使position盒子relative和课程跨度position absolute。例如,

box{
    position:relative;
    display:block;
}

.courses span{
    position:absolute;
    text-align: center;
}

尝试在代码中使用这些属性以及除属性之外的其他属性vertical-align

于 2017-05-20T16:08:53.760 回答