css图片旋转
时间: 2023-07-25 19:11:21
浏览: 18
要在 CSS 中旋转[图片](https://geek.csdn.net/educolumn/1de9845baad351038ab25b200eff4431?spm=1055.2569.3001.10083),可以使用 `transform` 属性中的 `rotate` [函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)。以下是一个示例[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083):
```css
img {
transform: rotate(45deg);
这将会使[图片](https://geek.csdn.net/educolumn/1de9845baad351038ab25b200eff4431?spm=1055.2569.3001.10083)顺时针旋转 45 度。你可以根据需要更改角度值。如果你只想将图片水平或垂直翻转,可以使用 `scale` [函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)来实现:
```css
img {
transform: scaleX(-1); /* 水平翻转 */
transform: scaleY(-1); /* 垂直翻转 */
同样地,你也可以根据需要更改缩放值。
相关问题
css 图片旋转180°
要实现CSS图片旋转180度,可以使用以下代码片段:
.box img:nth-of-type(1){
transform: rotateX(0deg); /*第一张照片旋转0度*/
.box img:nth-of-type(2){
transform: rotateX(-180deg); /*第二种照片旋转-180度,不显示*/
这段代码中,`.box img:nth-of-type(1)`表示选择`.box`元素中的第一个`img`子元素,然后通过`transform`属性的`rotateX`函数将其旋转0度。`.box img:nth-of-type(2)`表示选择`.box`元素中的第二个`img`子元素,通过`transform`属性的`rotateX`函数将其旋转-180度,从而使其不显示。当鼠标悬停在`.box`元素上时,`.box:hover img:nth-of-ty
css图片旋转45°
相关推荐















