When I rotate and inline layer with TEXT, it adds extra space (width of large text) on the rotation, I dont want to fix. What is the best way to avoid extra space (width of element) on both sides when rotating with CSS.
Below is my Code:
.rotate {
display: inline-block;
white-space: nowrap;
transform: translate(0, 100%) rotate(-90deg);
transform-origin: 0 0;
vertical-align: bottom;
}
.rotate:before {
content: "";
float: left;
margin-top: 100%;
}
.rotate:after {
content: "";
display: inline-block;
}
<div style="display:inline-block; position:relative;" class="rotate">
<span style="displock;width:100%;font-size: 55px;color: #222222;opacity: 0.15;white-space: nowrap;">BACKGROUND</span>
<span style="display:block;width:100%;font-size: 45px;color: #222222;text-align:center;">TITLE</span>
</div>
Some randome text here should be close to the rotated element Some randome text here should be close to the rotated element Some randome text here should be close to the rotated element
Here you go:
http://jsfiddle.net/9Y7Cm/13205/
vertical-align
is the key to answer.transforms
are entirely visual...they do NOT affect the layout of elements. Space is not being added...it's there all the time.Consider using
writing-mode
instead.Very simple answer
You may try to use
writing-mode
.https://codepen.io/gc-nomade/pen/rGJGzQ?editors=1100
or
transform:rotate(-90deg)
(which was your first choice), but with a pseudo to reset height according to text-length. (this requires to use rgba() colors and set both line of text in a single container. https://codepen.io/gc-nomade/pen/RLQLJG?editors=1100Both technics here, requires to set a width to the rotating text container and are build from a flex container. It should work in IE,FF,Chrome. (
display:table/table-cell
can be another display option for older browser)