2017-07-19 119 views
0

我有長桌子,我想旋轉它,問題是,當我旋轉它時,它在左邊裁剪。這裏是我的小提琴:CSS旋轉被裁剪

.rotate { 
 
    /* 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); 
 
}
<table class="rotate"> 
 
    <tr> 
 
    <td>Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Ametv</td> 
 
    </tr> 
 
</table>

,你可以看到,表格的左邊部分被裁剪。無論如何創建這張表沒有被裁剪?我不能使用保證金,因爲表格的內容各不相同。有時更長或更短。

回答

0

默認情況下,元素從元素的中心變換。您要查找的是設置的轉換從元件的底部發起,與transform-origin: bottom

.rotate { 
 
    /* 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); 
 
    
 
    /* Origin */ 
 
    transform-origin: bottom; 
 
}
<table class="rotate"> 
 
    <tr> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    </tr> 
 
</table>

希望這有助於! :)

+0

我試着變換出身,但仍冒出了很長的桌子。我嘗試最高價值,但頂部/左側仍然裁剪 –

+0

如果上述解決方案不能解決您的問題,您需要提供[**最小,完整和可驗證的示例**](http:// stackoverflow。 com/help/mcve) - 上面解決了Stack Snippet中的問題。 –

+0

我試圖擴大你的片段,它也裁剪了太多... –

0

我認爲計算px屬性值transform-origin像下面應該解決這個問題。

Transform origin

var height = $(".rotate").outerHeight(); 
 

 
var xaxis = height/2 + 'px'; 
 
var yaxis = height/2 + 'px'; 
 

 
$('.rotate').css({ 
 
    'transform-origin': '' + xaxis + ' ' + yaxis + ' 0px' 
 
});
.rotate { 
 
    background-color: lightgray; 
 
    border: 1px solid gray; 
 
    transform: rotate(90deg); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table class="rotate"> 
 
    <tr> 
 
    <td>Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem 
 
     Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem 
 
     Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    <td>Lorem Ipsum Dolor Sit Amet</td> 
 
    </tr> 
 
    <tr> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum</td> 
 
    <td>Lorem Ipsum Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit 
 
     Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Amet 
 
     Lorem Ipsum Dolor Sit Amet Lorem Ipsum Dolor Sit Ametv</td> 
 
    </tr> 
 
</table>