Force word wrap through CSS

后端 未结 7 1214
忘掉有多难
忘掉有多难 2021-01-04 00:10

At the moment TEST TEST appear side by side. How can I push one down onto a second line? Only through CSS.

TEST TEST

7条回答
  •  别那么骄傲
    2021-01-04 00:18

    You need to set the width of the div element. The elements will then roll over to the new line automatically.

    #box{
        width:20px; /* or a suitable width*/
        height: 50px;
        text-align: center;
        position: relative;
        margin: 0 auto;
        background-color: red;
        color: white;
        display: inline-block;
        padding-left: 5px;
        padding-right: 5px;
    }
    

    Note, however, that the height becomes dependent on the content. If there is allot of content then the element height will also increase.

    And alernative approach is to set the word spacing for the parent container to a high amount, eg,

    .parent {
      word-spacing:; 
    }
    

    That will also force word wrap after each word.

提交回复
热议问题