CSS层叠样式表—CSS超链接样式

超链接样式

学习目标

在这里插入图片描述

超链接伪类

在CSS中,我们可以使用“超链接伪类”来定义超链接在鼠标点击的不同时期的样式。

语法:

a:link{}
a:hover{}
a:active{}
a:visited{}

说明:

伪类说明
a:link定义a元素未访问时的样式
a:active定义鼠标点击激活时的样式
a:hover定义鼠标经过a元素时的样式
a:visited定义a元素访问后的样式

注意:如果在使用的时候没有展示未访问时的样式,这时候我们去清空我们的浏览器历史记录就可以实现效果了。

<!DOCTYPE html> 
<html>
<head>
    <meta charset="utf-8" />
    <title> </title>
    <style type="text/css">
        a {
            text-decoration:none;
        }
        a:link {
            color:red;
        }
        a:visited {
            color:purple;
        }
        a:hover {
            color:yellow;
        }
        a:active {
            color:blue;
        }
    </style>
</head>
<body>
    <a href="http://www.baidu.com" target="_blank">百度</a>
</body>
</html>

深入了解:hover

hover应用在其他标签上的效果。

语法:

元素:hover{}

举例:“:hover”用于div

<!DOCTYPE html> 
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        div{
            width:100px;
            height:30px;
            line-height:30px;
            text-align:center;
            color:white;
            background-color: lightskyblue;
        }
        div:hover{
            background-color: hotpink;
        }
    </style>
</head>
<body>
    <div>hover效果颜色</div>
</body>
</html>

举例::hover用于img

<!DOCTYPE html> 
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        img:hover {
            border:2px solid red;
        }
    </style>
</head>
<body>
    <img src="img/girl.gif" alt="">
</html>

鼠标样式

MDN:https://developer.mozilla.org/zh-CN/docs/Web/CSS/cursor

在CSS中,我们可以使用cursor属性来定义鼠标样式。

语法:

cursor: 取值;

说明:

cursor属性取值如下表所示。在实际开发中我们一般只会用到3个:default、pointer和text。其他的很少用得上,所以就不需要去记忆了。

属性值外观
default默认值
pointer小手
text文本
move箭头
<!DOCTYPE html> 
<html>
<head>
    <meta charset="utf-8" />
    <style type="text/css">
        div{
            width:100px;
            height:30px;
            line-height:30px;
            text-align:center;
            background-color: hotpink;
            color:white;
            font-size:14px;
        }
        #div_default{
            cursor:default;
        }
        #div_pointer{
            cursor:pointer;
        }
    </style>
</head>
<body>
    <div id="div_default">鼠标默认样式</div>
    <div id="div_pointer">鼠标手状样式</div>
</body>
</html>

除了使用浏览器自带的鼠标样式,我们还可以使用cursor属性来自定义鼠标样式。只不过语法稍微有点不一样。

语法:

cursor: url(图片地址), 属性值;

说明:

这个“图片地址”是鼠标图片地址,其中鼠标图片后缀名一般都是.cur,我们可以使用Photoshop来制作,小伙伴们自行搜索一下制作方法。

而这个“属性值”一般为3种:default、pointer和text。

<!DOCTYPE html> 
<html>
<head>
    <meta charset="utf-8" />
    <style type="text/css">
        div{
            width:100px;
            height:30px;
            line-height:30px;
            text-align:center;
            background-color: hotpink;
            color:white;
            font-size:14px;
        }
        #div_default{cursor:url(img/cursor/default.cur),default;}
        #div_pointer{cursor:url(img/cursor/pointer.cur),pointer;}
    </style>
</head>
<body>
    <div id="div_default">鼠标默认样式</div>
    <div id="div_pointer">鼠标手状样式</div>
</body>
</html>

课程总结

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值