javascript - Set height on div with CSS3 transform (rotate) -


goal

i'm working on collapsible sidebar using jquery animation. have vertical text on sidebar acts label , can swap on animateout/animatein effect.

normally use image of text i've swapped vertically, , switch out on animation, css3 transforms i'd work instead.

problem

the problem i'm facing setting height on rotated container makes expand horizontally (as it's rotated 90deg) doesn't work. tried set width (hoping expand vertically, acting height), has odd effect of causing width of parent container expand well.

fix?

how can set height on rotated (transformed) element without affecting width of parent container? far have been unable this.

live example

here's fiddle demonstrates problem: fiddle

the collapse-pane class have rotated , contains span have text inside. you'll notice has width set, widens border, affects parent container.

the code:

css:

.right-panel{     position:fixed;     right:0;     top:0;     bottom:0;     border:1px solid #ccc;     background-color:#efefef; } .collapse-pane{     margin-top:50px;     width:30px;     border:1px solid #999;     cursor:pointer;     /* safari */     -webkit-transform: rotate(-90deg);     /* firefox */     -moz-transform: rotate(-90deg);     /* ie */     -ms-transform: rotate(-90deg);     /* opera */     -o-transform: rotate(-90deg);     /* internet explorer */     filter: progid:dximagetransform.microsoft.basicimage(rotation=3);    } .collapse-pane span{     padding:5px; } 

html

<div class="right-panel">     <div class="collapse-pane">         <span class="expand">expand</span>     </div>     <div style="width:0;" class="panel-body">         <div style="display:none;" class="panel-body-inner">             adsfasdfasdf         </div>     </div> </div> 

here's image showing problem, don't have view fiddle.

weird div spacing

update

i've made problem statement little clearer, original post confusing issues.

thanks help!

if don't want rotated divs size expand it's parent size, need take out of flow. may use absolute positioning this.

the following demo uses technique , positions "expand" element setting transform orign , top/right values.

demo

css :

.right-panel {     position:fixed;     right:0;     top:0;     bottom:0;     border:1px solid #ccc;     background-color:#efefef; } .collapse-pane {     position:absolute;     border:1px solid #999;     cursor:pointer;     top:20%;     right:100%;     -ms-transform-origin:100% 100%;     -webkit-transform-origin: 100% 100%;     transform-origin: 100% 100%;     /* safari */     -webkit-transform: rotate(-90deg);     /* firefox */     -moz-transform: rotate(-90deg);     /* ie */     -ms-transform: rotate(-90deg);     /* opera */     -o-transform: rotate(-90deg);     /* internet explorer */     filter: progid:dximagetransform.microsoft.basicimage(rotation=3); } .collapse-pane span {     padding:5px; } 

jquery :

$(document).ready(function () {     var height = $(".right-panel").height();     $('.collapse-pane').click(function () {         if ($(".collapse-pane span").html() == "expand") {             $(".panel-body").animate({                 width: 200             }, 400);             $(".panel-body-inner").fadein(500);             $(".collapse-pane span").html("collapse");         } else {             $(".panel-body").animate({                 width: 00             }, 400);             $(".panel-body-inner").fadeout(300);             $(".collapse-pane span").html("expand");         }     }); }); 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -