when you use a transform or position: relative; the initial space used by the element remains unchanged, it is drawn only on the screen.
Here, if you want your rotating block to use only the width of one line, you need to set this width and allow the content to overflow.
translate can be used to replace content in view
white-space: nowrap to save text on one line
and ultimately, due to the use of the rotated value and reduced width, you can use the direction to 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%); }
<div class="pane"> <span class="vertical">This is text</span> </div> <div class="pane"> <span>This is another Pane</span> </div>
Alternatively, you can use min-width and negative margin, which actually reduces the width of the elements to none;
I would like to make it even simpler and more reliable.
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%); }
<div class="pane"> <span class="vertical">This is text</span> </div> <div class="pane"> <span>This is another Pane</span> </div> <div class="pane"> <span class="vertical">This is some more text</span> </div>
source share