Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS rotate div 90 degrees to left margin

I have a div that contains one or more buttons. It can be rotated 90 degrees. But I need the rotated div to place along left margin (Y-Axis) and vertically aligned to middle of Y-Axis.

I started trying a fiddle - http://jsfiddle.net/5rnm577a/

The code is given below:

HTML:

<div>
    <div id="yaxisbuttons">
        <p>Y Button 1</p>
        <p>Y Button 2</p>
    </div>
</div>

CSS:

#yaxisbuttons {
    padding:0px 0px 0px 0px;
    text-align: center;
    margin:0px;
    width: 160px;
    height:40px;
    background:#FF931E;
    z-index:15;
    border-radius: 5px 5px 5px 5px;
    -moz-transform:rotate(-90deg);
    -ms-transform:rotate(-90deg);
    -o-transform:rotate(-90deg);
    -webkit-transform:rotate(-90deg);
}

Can someone please help?

like image 950
dr janes Avatar asked Sep 13 '15 06:09

dr janes


People also ask

How to rotate text 90 degrees in CSS?

How to Rotate Text 90 degrees in CSS? Rotation in CSS is mostly performed using the transform property. This property supports several rotation methods such as rotateX (), rotateY (), rotate (), rotate3d (), etc. which allows you to rotate any HTML element.

How to rotate the HTML <div> element using CSS transform?

Solution with the CSS transform property ¶ Before showing how to rotate the HTML <div> element, it should be noted that applying the 90deg rotation to the square would result in the same appearance. You need to add the width and height properties for the container and specify the transform property with the “rotate (90deg)” value.

How to rotate an element 90 degrees in Revit?

Last Updated : 16 Oct, 2019 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.

What is the use of rotation in CSS?

Definition and Usage. The rotation property rotates a block-level element counterclockwise around a given point defined by the rotation-point property. Tip: The border, padding, content, and backgrounds (that are not fixed) are also rotated!


2 Answers

A lot depends on what you select as the transform-origin point.

In addition to the rotation you have to translate the element up/down/left/right as required.

To position the element 50% down the page(?) you will need to use, erm, positioning...I used absolute here but fixed would work just as well.

* {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
body {
  margin: 0;
  padding: 0;
  height: 300px;
  width: 300px;
}
#yaxisbuttons {
  position: absolute;
  top: 50%;
  padding: 0 5px;
  text-align: center;
  background: #FF931E;
  border-radius: 5px;
  transform-origin: center top;
  transform: translateX(-50%) rotate(-90deg);
}
#yaxisbuttons p {
  color: #fff;
  line-height: 20px;
  display: inline-block;
}
.line {
  position: absolute;
  top: 50%;
  width: 100%;
  height: 1px;
  border-bottom: 1px solid red;
}
<div id="yaxisbuttons">
  <p>Y Button 1</p>
  <p>Y Button 2</p>
</div>
<div class="line"></div>

I added a reference line for visual confirmation of the positioning for the purposes of this demo.

like image 71
Paulie_D Avatar answered Oct 13 '22 07:10

Paulie_D


Can you explain more by drawing image?

You can use this code below.

#yaxisbuttons {
    padding: 0px 0px 0px 0px;
    text-align: center;
    margin: 180px 0 0 0px;/*Changed*/
    width: 160px;
    height: 40px;
    background: #FF931E;
    z-index: 15;
    border-radius: 5px 5px 5px 5px;
    -moz-transform: rotate(-90deg);
    -ms-transform: rotate(-90deg);
    -o-transform: rotate(-90deg);
    -webkit-transform: rotate(-90deg);
    transform-origin: left top;/*New Added*/
}

Live Demo on jsfiddle

like image 40
Sarower Jahan Avatar answered Oct 13 '22 07:10

Sarower Jahan