CSS怎么设置鼠标悬停样式?怎么更改鼠标样式。

猿友 2021-05-21 13:56:40 浏览数 (4895)
反馈

网页上不同区域的鼠标悬停样式是不一样的,比如链接上的是小手,文字编辑区域是一个“I”,普通的则是箭头。那么如果我们想要更改鼠标样式应该怎么做呢?这篇文章告诉你 CSS 怎么设置鼠标悬停样式。

cursor 属性

cursor 属性是用来设置鼠标悬停样式的。其属性值如下:

  • default:默认样式,箭头
  • auto:默认浏览器设置的光标
  • crosshair:十字线
  • pointer:光标指示链接(一只小手)
  • move:此光标表示对象可被移动
  • text:此光标指示文本
  • wait:此光标表示程序正忙(沙漏或手表)
  • help:此光标表示可用的帮助(问号或气球)
  • 其他样式可前往 cursor 属性查询。
具体代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>CSS设置鼠标悬停样式 - 编程狮(w3cschool.cn)</title>
	<style type="text/css">
		#crosshair{
			cursor: crosshair;
		}
		#pointer{
			cursor: pointer;
		}
		#move{
			cursor: move;
		}
		#text{
			cursor: text;
		}
		#wait{
			cursor: wait;
		}
		#help{
			cursor: help;
		}
	</style>
</head>
<body>
	<p>默认样式</p>
	<p id="crosshair">十字线</p>
	<p id="pointer">一只小手</p>
	<p id="move">可被移动</p>
	<p id="text">指示文本</p>
	<p id="wait">表示程序正忙</p>
	<p id="help">表示可用帮助</p>
</body>
</html>

由于截图不能将鼠标指示光标展现出来,此处就不展示效果,感兴趣的同学们可以自行实践一下。

以上就是文章“CSS 怎么设置鼠标悬停样式?怎么更改鼠标样式。”的全部内容。想要了解更多 CSS 资料,请前往 w3cschool

CSS

0 人点赞