How do you align 270deg rotated text to top left?

前端 未结 2 1533
Happy的楠姐
Happy的楠姐 2021-02-07 10:07

This should be a very simple problem you would think. I have a box with some title text that I want to rotate -90 degrees. I would like it to be absolutely positioned so that th

2条回答
  •  我在风中等你
    2021-02-07 10:36

    You should use transform-origin to adjust the transformation point, along with some creative use of positioning properties.

    http://jsfiddle.net/thirtydot/JxEfs/1/

    CSS:

    #box {
        padding: 30px;
        position: relative;
        border: 1px solid blue;
    }
    #box > div {
        border: 1px solid red;
        position: absolute;
        top: 0;
        right: 100%;
        white-space: nowrap;
    
        -webkit-transform: rotate(270deg);
        -webkit-transform-origin: right top;
        -moz-transform: rotate(270deg);
        -moz-transform-origin: right top;
        -ms-transform: rotate(270deg);
        -ms-transform-origin: right top;
        -o-transform: rotate(270deg);
        -o-transform-origin: right top;
        transform: rotate(270deg);
        transform-origin: right top;
    }
    

    HTML:

    hello
    rotated!

提交回复
热议问题