开发者

CSS Drawing on an Angle

My CSS looks as follows:

.block1 {

 height:20px;
 width:70px;
 background-color:#09F;
 background-repeat:no-repeat;
 position:absolute;

}

This draws a 开发者_开发技巧rectangle. Next i would like to draw a rectangle on an angle, such as at 45 degrees. I am not aware of an angle option, how could i do this?


It's not fully supported in all browsers, but you can use CSS Rotation. Here's an article on it.

Basically, apply:

-moz-transform:rotate(45deg); /* Firefox */
-webkit-transform:rotate(45deg); /* WebKit (Chrome, Safari) */
-o-transform: rotate(45deg); /* Opera */
-ms-transform:rotate(45deg); /* IE9 */
transform: rotate(45deg); /* No support currently, but hooray future! */

/* Fun IE code (you should probably put this in a separate css file controlled with conditional comments) */
/* IE8+ - must be on one line, unfortunately */ 
-ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865474, M12=-0.7071067811865477, M21=0.7071067811865477, M22=0.7071067811865474, SizingMethod='auto expand')";  
/* IE6 and 7 */ 
filter: progid:DXImageTransform.Microsoft.Matrix(
         M11=0.7071067811865474,
         M12=-0.7071067811865477,
         M21=0.7071067811865477,
         M22=0.7071067811865474,
         SizingMethod='auto expand');
/* These are necessary for the IE code only */
margin-left: 5px; 
margin-top: -70px;

IE code generated with this tool, which is incredibly useful.


You should use transform (from CSS3) with the value rotate(45deg), and the vendor prefixed property variants:

See: http://jsfiddle.net/JngyN/

-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg); 

Making it work properly in older versions of IE is.. difficult.

I recommend that you use this tool which makes it relatively easy:

http://www.useragentman.com/IETransformsTranslator/index.html


here is the IE version for matrix

filter:progid:DXImageTransform.Microsoft.Matrix(M11=0.7071, M12=-0.7071, M21=0.7071, M22=0.7071, SizingMethod='auto expand');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜