CSS 背景图旋转的问题

在学习CSS的过程中遇到以下问题:

clipboard.png
蓝色箭头所指的白色小箭头是向右的,我想把它旋转到向下,这个应该怎么做呢?
附上代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>背景颜色</title>
    <style>
        #nav {
            width: 230px;
            background-color: #D7D7D7;
        }
        .title {
            background-color: #C00;
            font-size: 18px;
            font-weight: bold;
            color: #FFF;
            text-indent: 1em;
            line-height: 35px;
            background-image: url("bg.png");
            background-repeat: no-repeat;
            background-position: 205px 10px;
        }
        #nav ul li {
            height: 30px;
            line-height: 25px;
            list-style: none;
            background-image: url("bg.png");
            background-repeat: no-repeat;
            background-position: 170px 2px;
        }
        a {text-decoration: none}
    </style>
</head>
<body>

<div  id="nav">
    <h2 class="title">全部商品分类</h2>
    <ul>
        <li>
            <a href="">图书</a>&nbsp;&nbsp;<a href="">音像</a>&nbsp;&nbsp;<a href="">数字商品</a>
        </li>
        <li>
            <a href="">家用电器</a>&nbsp;&nbsp;<a href="">手机</a>&nbsp;&nbsp;<a href="">数码</a>
        </li>
        <li>
            <a href="">电脑</a>&nbsp;&nbsp;<a href="">办公</a>
        </li>
        <li>
            <a href="">家居</a>&nbsp;&nbsp;<a href="">家装</a>&nbsp;&nbsp;<a href="">厨具</a>
        </li>
        <li>
            <a href="">服饰鞋帽</a>&nbsp;&nbsp;<a href="">个护化妆</a>
        </li>
        <li>
            <a href="">礼帽箱包</a>&nbsp;&nbsp;<a href="">钟表</a>&nbsp;&nbsp;<a href="">珠宝</a>
        </li>
        <li>
            <a href="">食品饮料</a>&nbsp;&nbsp;<a href="">保健食品</a>
        </li>
        <li>
            <a href="">彩票</a>&nbsp;&nbsp;<a href="">旅行</a>&nbsp;&nbsp;<a href="">充值</a>&nbsp;&nbsp;<a href="">票务</a>
        </li>
    </ul>
</div>

</body>
</html>

如果是用transform:rotate,只能把整个标题块旋转过来,问题是我只想转这个小箭头

阅读 17.9k
4 个回答

把这个箭头放在一个标签里,常用的是i标签或span,然后旋转这个标签,像这种小图标可以不用图片的

为啥用背景图,after不是更改吗

你只能把你的箭头图从背景中拿出来,以元素的形式重新定位到指定位置,我印象中是不能对背景图单独做旋转操作的

箭头放在伪类里面

.title {
    position: relative;
    padding-right: 30px;
}
.title:after {
    content: '';
    position: absolute;
    display: block;
    width: 15px;
    height: 15px;
    top: 10px;
    right: 10px;
    background-image: url("bg.png");
    background-repeat: no-repeat;
    background-size: cover;
}
.title.rotate:after {
    transform: rotate(180deg);
    -webkit-transform: rotate(180deg);
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题