Break letters of second child div

后端 未结 6 1166
臣服心动
臣服心动 2021-01-12 16:24

I have one requirement, where I need to apply width to the parent element which is equal to the first child element\'s width. This can be easily achieved using display

6条回答
  •  迷失自我
    2021-01-12 17:15

    I don't think you will be able to achieve it without a little help of javascript. Imagine the the following markup and css :

    first
    valuevalue

    and then the following css :

    .main{
        background-color : red;
        display: inline-block;
        max-width: 50px;
    }
    .first{
        background-color : blue;
    }
    .second{
        background-color : green;
    }
    .content{
         word-break: break-word;
    }
    

    Now all you gotta do is to set the max-width of your .main div to be equal to your first element and add the content class to each element. I suppose you are adding your elements dynamically.

提交回复
热议问题