Display block without 100% width

后端 未结 8 1057
谎友^
谎友^ 2020-12-12 21:27

I want to set a span element to appear below another element using the display property. I tried applying inline-block but without success, and figured I could use block if

8条回答
  •  一整个雨季
    2020-12-12 21:59

    I had this issue, I solved it like so:

    .parent {
      white-space: nowrap;
      display: table;
    }
    
    .child {
      display: block;
    }
    

    the "white-space: nowrap" makes sure that the children of the child(if it has any) don't wrap to new line if there is not enough space.

    without "white-space: nowrap" :

    with "white-space: nowrap" :


    edit: it seems that it also just works without the child block part for me, so just this seems to work fine.

    .parent {
      white-space: nowrap;
      display: table;
    }
    

提交回复
热议问题