CSS3 transform an element but not its descendants

和自甴很熟 提交于 2019-12-24 12:03:28

问题


I have an horizontal menu and I want to rotate 90° left or right some of its tabs. Problem is that the transform property also rotates descendants. It looks difficult to put them back in place, is there a solution?

P.S. I want to avoid using images or JS, they are ok as fallbacks.


回答1:


You could apply the reverse rotation on the descendants.

For example

div.parent{
    -webkit-transform: rotate(-90deg); 
    -moz-transform: rotate(-90deg); 
}


div.parent span{
    -webkit-transform: rotate(90deg); 
    -moz-transform: rotate(90deg);  
}

Example: http://jsfiddle.net/RpcfB/1/

Fyi, you will need to play with padding and/or margin to make it all work.

EDIT

I'm afraid it's more complicated than that.

That's the truth!! Although, I as mentioned, you have to play with the css.

For example, to fix the first one, you need to make these adjustments:

  1. add a class to the first li

     #nav_main_gts > li.rotate{ //ADD CLASS HERE
         -moz-transform: rotate(-90deg);
         -webkit-transform: rotate(-90deg);
         -o-transform: rotate(-90deg);
         -ms-transform: rotate(-90deg);
         filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=-1);
         transform: rotate(-90deg);
     }
    
  2. Then change the second rule to target the next ul not li

  3. Then fiddle with the margin to get it all in place. Remember, because the first li is rotated, down is not left, so a negative margin-left is needed

     #nav_main_gts > li.rotate ul{ //CHANGE TO UL HERE
        -moz-transform: rotate(90deg);
        -webkit-transform: rotate(90deg);
        -o-transform: rotate(90deg);
        -ms-transform: rotate(90deg);
        filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
        transform: rotate(90deg);
        margin-left:-100px;  //ADD A MARGIN HERE
     }
    
  4. continue with the others.

Updated example: http://jsfiddle.net/FKCTk/1/



来源:https://stackoverflow.com/questions/7514200/css3-transform-an-element-but-not-its-descendants

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!