简体   繁体   English

以不同的方向显示图像,不使用javascript,而仅显示html和css

[英]Display an image in its different orientation without javascript, but only html and css

I have a cheque image to display which is in the landscape orientation (horizontally), but need to be displayed in the portrait orientation (vertically). 我有一张要显示的支票图像,它是横向(水平)的,但是需要以纵向(垂直)显示。 But the web site has requirements of not supporting JavaScript. 但是该网站要求不支持JavaScript。

For example, the below one, if I apply rotate transform, the image will turn 90 degrees clockwise and display in the portrait orientation as I wish, but it also doesn't fit in its parent DIV anymore. 例如,在下面的示例中,如果我应用旋转变换,则图像将按顺时针方向旋转90度并按我的意愿以纵向显示,但它也不再适合其父级DIV。 How can I fix this? 我怎样才能解决这个问题?

 <div style='border:1px solid red;'> DIV 1 </div> <div style='border:1px solid red;'> An <img src="http://www.outreachaz.com/images/EMD%20Check.jpg" />image! </div> <div style='width:100%; border:1px solid red;'> DIV 2 </div> 

 .rotate90 { -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -o-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } 
 <div style='border:1px solid red; margin-top:100px'> DIV 1 </div> <div style='border:1px solid red;'> An <img class='rotate90' src="http://www.outreachaz.com/images/EMD%20Check.jpg" />image! </div> <div style='width:100%; border:1px solid red;'> DIV 2 </div> 

Here's how it will fit (code taken from first draft of answer) : 这是适合的方式(代码来自答案初稿):

.VerticalAlign {
height: 300px;
}

.rotate90 {
position: relative;
top: 50%;
-webkit-transform-origin: top center;
transform-origin: top center;
-webkit-transform: rotate(90deg) translateY(-50%);
transform: rotate(90deg) translateY(-50%);
}

http://jsfiddle.net/dxweu9v5/ http://jsfiddle.net/dxweu9v5/

If the intention is to let the parent adapt to the rotated size, that is not possible without JavaScript : 如果要让父级适应旋转后的大小,那么在没有JavaScript的情况下是不可能的:

Rotated elements in CSS that affects their parent's height correctly CSS中的旋转元素会正确影响其父对象的高度

You just need to add overflow: auto to the containing div . 您只需要将overflow: auto添加到包含的div

 .rotate90 { -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -o-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } 
 <div style='border:1px solid red; margin-top:100px'> DIV 1 </div> <div style='border:1px solid red;overflow: auto'> An <img class='rotate90' src="http://www.outreachaz.com/images/EMD%20Check.jpg" />image! </div> <div style='width:100%; border:1px solid red;'> DIV 2 </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM