rotating text slightly—should I use css or javascr

2019-07-19 07:52发布

I'm trying to rotate a block of text slightly like below:

enter image description here

Can this be done with css or do I need to use javascript?

4条回答
神经病院院长
2楼-- · 2019-07-19 08:07

You can do it in a cross browser fashion using CSS3's transform, and a filter for IE.

See: http://jsfiddle.net/dRQaw/

This is the magical tool used to generate the cross-browser CSS.

<div id="skewed">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu metus nisi. Integer non adipiscing massa. Etiam et diam magna. Mauris sit amet arcu dui, a malesuada erat.</div>

#skewed {
    font: 21px Impact, sans-serif;
    text-align: center;
    background: #ccc
}
#skewed {
     width:             350px;
     height:            140px;

     -moz-transform:    skew(-5deg, -5deg);
     -o-transform:      skew(-5deg, -5deg);
     -webkit-transform: skew(-5deg, -5deg);
     transform:         skew(-5deg, -5deg);
}    
查看更多
做个烂人
3楼-- · 2019-07-19 08:11

It'd be CSS-only. You can use JS to manipulate the CSS, but JS itself has nothing to do whatsoever with presentation, other than being one method of changing the presentation rules.

查看更多
倾城 Initia
4楼-- · 2019-07-19 08:15

You could use CSS. Here is CSS that will work in Firefox, Opera and Safari/Chrome.

#textToRotate {
  -webkit-transform: rotate(-10deg);
  -moz-transform: rotate(-10deg);
  -o-transform: rotate(-10deg);
}
查看更多
forever°为你锁心
5楼-- · 2019-07-19 08:28

You can do it with CSS3 transforms:

p {
  -moz-transform: rotate(-15deg);
  -o-transform: rotate(-15deg);
  -ms-transform: rotate(-15deg);
  -webkit-transform: rotate(-15deg);
  transform: rotate(-15deg);
}
查看更多
登录 后发表回答