Resize div when content is rotated

后端 未结 1 411
天命终不由人
天命终不由人 2021-01-14 00:11

I don\'t know that my question is much different than the question in the possible duplicate. However, the answer in the possible duplicate does not work (even the jsFiddle

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-14 01:04

    when you use transform or position:relative; the initial space used by the element remains the same, it is only drawn different at screen.

    Here if you want your rotated box to only use the width of one line height, you need to set this width and let content overflow.

    translate can be used to replace content in sight

    white-space:nowrap to keep text on a single line

    and eventually, because of the rotated value used and the width reduced, you may use direction to push overflow in the opposite direction .

    html,
    body {
      height: 100%;
      margin: 0px;
    }
    
    .pane {
      width: auto;
      float: left;
      height: 100%;
      border: 1px solid black;
    }
    
    .vertical {
      display: inline-block;
      text-align: left;
      float: right;
      padding-right: 1em;
      width: 0.25em;
      white-space: nowrap;
      direction: rtl;
      transform-origin: top left;
      transform: rotate(-90deg) translate(-100%);
    }
    This is text
    This is another Pane

    Else you may use min-width , and a negative margin that virtually reduce elements width to none;

    I would go for this one more simple and solid

    html,
    body {
      height: 100%;
      margin: 0px;
    }
    
    .pane {
      width: auto;
      min-width:1.2em;
      float: left;
      height: 100%;
      border: 1px solid black;
    }
    
    .vertical {
      display:inline-block;
      padding-right:0.25em;
      margin-right:-999px;
      transform-origin: top left;
      transform: rotate(-90deg) translate(-100%);
    }
    This is text
    This is another Pane
    This is some more text

    0 讨论(0)
提交回复
热议问题