Search code examples
jquerycsstransform

How to position rotated text to the right of image


I am trying to position a vertical (rotated) copyright notice to the right of an image using css. I can almost get it working, but it still positions the text relative to the page, which is not a workable option (it must position relative to the picture or containing div). I'd prefer to use a pure css solution, but if that isn't possible, I'd also welcome JQuery solutions.

Example: http://jsfiddle.net/s5zYj/4/

Edit: I should have specified that I'm looking for a general solution, which works for any reasonable length name (not just Mickey Mouse).

HTML

<div>
    Some text <br /><br /><br /><br />
</div>
<div>
    <img class="caption" src="http://lorempixel.com/g/400/300/cats/"/>
        <span class="image-copyright"><small>&copy; Mickey Mouse</small></span>
</div>

CSS

.image-copyright {
    position: absolute;
    float: right;
    transform: rotate(-90deg);
    transform-origin:100% 100%;
    -ms-transform: rotate(-90deg); /* IE 9 */
    -ms-transform-origin:100% 100%; /* IE 9 */
    -webkit-transform:rotate(-90deg);
    -webkit-transform-origin: 100% 100%;
    z-index: 100;
    color: gray;
    right: 58px;
}

Desired result

enter image description here


Solution

  • I used this css

    .image-copyright {
    position: absolute;
    
    transform: rotate(-90deg);
    transform-origin:100% 100%;
    -ms-transform: rotate(-90deg); /* IE 9 */
    -ms-transform-origin:100% 100%; /* IE 9 */
    -webkit-transform:rotate(-90deg);
    -webkit-transform-origin: 100% 100%;
    z-index: 100;
    color: gray;
    right: -20px; /*edited*/
    top:-18px;
    }
    
    #container {
    position:relative;
    background:yellow;
    display:inline-block;
    }
    

    and I gave the parent div for the img, an id of "container".