当列表项超出容器的宽度时,将其中断到新行

时间:2018-12-11 13:19:47

标签: html css

我在一个position:absolute容器div中有一个div relativeabsolute位置div的宽度是一个百分比,当我减小浏览器大小从而缩小div的大小时,li文本将被截断,我将包括屏幕截图。我希望li中的文本可以换行而不写<br>,因为它们将动态生成。好的,这是我的代码

// HTML

<div class="information-toggle">
    <aside class="information-toggle__list">
        <ul>
            <li>Meaningless Existence</li>
            <li>Meaningless Existence</li>
            <li>Meaningless Existence</li>
            <li>Meaningless Existence</li>
        </ul>
    </aside>
    <div class="information-toggle__content">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    </div>
</div>

// SASS

.information-toggle{
    // border:1px solid red;
    position:relative;
    margin:0 auto;
    font-family: 'Avenir',sans-serif;
}
.information-toggle__list{
    width:100%;
    // border:1px dashed green;
    z-index: 100;
    position:relative;   
    @media only screen and (min-width: 768px) {
        position:absolute;
        width:25%;
    }
    ul{
        list-style-type: none;
        padding: 0;
        text-align: center;
        overflow-x:scroll;
        white-space: nowrap;
        @media only screen and (min-width: 768px) {
            display:list-item;
            overflow-x:initial;
        }
        li{
            background: $button-red;
            border-bottom: 2px solid #ffffff;
            font-weight: 500;
            @include font-size(2.0);
            letter-spacing: 0.08px;
            position: relative;
            height: 46px;
            line-height: 46px;
            display: inline-block;
            color: $white;
            margin: 5px;
            border-radius:5px;
            @media only screen and (min-width: 768px) {
                display:list-item;
                border-radius:initial;
                border-top-left-radius:5px;
                border-bottom-left-radius:5px;  
                margin:initial;
                height: 67px;
                line-height: 67px;
            }
            &:hover {
                background:$button-red-hover;
                @media only screen and (min-width: 768px) {
                    @include rightArrow();
                    font-weight:900;
                }
            }
        }
    }
}
.information-toggle__content{
    width: 100%;
    // border: 1px dashed orange;
    margin-left: auto;
    padding: 25px;
    background: $white;
    //transform: translateY(33px);
    @media only screen and (min-width: 768px) {
        padding: 50px;
        width: 75%;
        transform: translateY(33px);
    }
}

这就是我的样子 enter image description here

3 个答案:

答案 0 :(得分:2)

在父div上使用;

word-wrap:break-word;

Example

答案 1 :(得分:0)

li项目上放whitespace: normalheight: automin-height: 67px

答案 2 :(得分:0)

您可以将overflow-wrap: break-word;应用于父级div。