Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Positioning rotated div elements

Tags:

html

css

rotation

I am having some difficulty positioning a rotated div element. So far I have:

#side-banner {
transform: rotate(270deg); }

which rotates my div just fine. however, I am having trouble "Pinning" it to the left side. (IE normally I would do something along the lines as: position fixed, left 0px, height 100%, width: whatever).

like image 873
Michael Schmidt Avatar asked May 15 '13 00:05

Michael Schmidt


People also ask

How do I rotate a div by 90 degrees?

An element can be rotated 90 degrees by using the transform property. This property is used to move, rotate, scale and others to perform various kinds of transformation to elements. The rotate() transformation function can be used as the value to rotate the element.

How do I rotate a div?

The rotate() method rotates an element clockwise or counter-clockwise. This a normal div element.

How do I rotate an image 180 degrees CSS?

Rotating images in real-time with the rotate parameter To rotate the image by 180 degrees, we need to add rt-180 transformation parameter to the URL, as shown below. The resulting image is the same as passing 180deg to the rotate function in CSS.

How do I rotate an item in CSS?

CSS rotate() Let's take a look at the syntax for the rotate() function: transform: rotate(angle); The value “angle” represents the number of degrees the element should rotate. You can specify a rotate that is clockwise using a positive degree number (i.e. 45).


2 Answers

If you mean you want the banner rotated and be fixed on the left side of the browserwindow, you can use the transform-origin property. By default it is set to 50% 50%. That's 50% of the width and height of the element (the center of the element).

You can try setting the origin to 0% 0%. that's the upper-left corner of the banner and then rotate it around that corner. Now with the banner rotated, the origin has become the left-bottom corner of the banner. You can position it fixed on the left side of the browserwindow like this:

#side-banner {
    poition:fixed;
    left:0;
    top:50%;
    width:300px; /* after rotation this is the height */
    margin-top:150px; /* is 50% of width */
    transform: rotate(270deg);
    transform-origin:0% 0%; /* set to the upper-left corner */
    -ms-transform: rotate(270deg); /* IE 9 */
    -ms-transform-origin:0% 0%; /* IE 9 */
    -webkit-transform: rotate(270deg); /* Safari and Chrome */
    -webkit-transform-origin:0% 0%; /* Safari and Chrome */
}

Edit:
If you want the banner to be the same height as the browserwindow after the rotation, that can be done with javascript or jQuery. Like this:

var width = $(window).height();
var marginTop = Math.round(width / 2);

$('#side-banner').css({
    'width': width,
    'margin-top': marginTop
});
like image 122
cumul Avatar answered Nov 15 '22 22:11

cumul


I sure wish I could just leave a comment instead, because I am not 100% sure I understand the issue you are facing.

I feel that your problem can be solved by encapsulating your rotated banner div inside a normal one and set the container div's position as fixed and left: 0px. I set up a fiddle to show you what I mean:

http://jsfiddle.net/q7qgn/1/

HTML:

    <div class="pageContainer">
    <div class="bannerContainer">
        <div class="banner">
            &nbsp;banner
        </div>
        <br/>bannerContainer
    </div>
</div>

CSS:

 .pageContainer{
margin: 0px;
background-color: grey;
width: 400px;
height: 400px;
}

.bannerContainer{
background-color: green;
width: 100px;
height:200px;
position: fixed;
left: 0px;
}

.banner{
background-color: red;
width: 100px;
height: 100px;
transform: rotate(270deg);
-webkit-transform: rotate(270deg);
}

Hope this helps!

like image 27
Sheriff_McLawDog Avatar answered Nov 15 '22 21:11

Sheriff_McLawDog