网页css设置鼠标移动有特效

html-css06

网页css设置鼠标移动有特效,第1张

首先我们创建一个html文件,写出html文件的一些基础代码

然后我们在网页中新建一个div,并新建一个

无序列表并创建4个然后使用浏览器直接打开html文件,查看效果,可以看到我们创建的标签自带有一定的格式,

接下来我们使用下面的代码去除标签的格式,其中:list-style:none表示去除标签的格式width:160px表示设置标签的宽height:240px表示设置标签的高background:#666666表示设置标签的背景色float:left表示设置标签浮动显示,并且为左浮动margin-right:20px表示设置标签右外边距

刷新浏览器中html文件查看效果,

这里我们开始添加动画:

标签添加:

transition:transform 0.1s

transform表示变换的属性,0.1上表示表换所需要的时间另外给标签添加鼠标滑动属性

li:hover{cursor:pointertransform:translate(0,-10px)}

cursor:pointer表示鼠标滑过显示为小手形状

transform:translate(0,-10px)translate表示移动,第一个参数为水平移动值,第二个参数为垂直移动值,

进入浏览器直接查看效果,如下图实现了鼠标滑过块,块上移的动画特效,如下图:

1、假设图片外层DIV的class为pic,图片的大小是400*300,html代码可以写成下面这样:

<divclass="pic">

<imgsrc="abc.jpg"width="400"height="300"/>

</div>

2、如果希望鼠标经过时图片的尺寸变成600*450,那么在css里面只要这样定义就行了:picimg:hover{width:600pxheight:450px}

3、这个代码在ie6下会不生效,因为ie6不支持除A标签外的其他元素的:hover伪类。如果要在ie6下兼容,只需要把div改成a标签,也就是在图片上加一个超链接,然后给它加上一个class即可。

鼠标

鼠标是计算机的一种输入设备,分有线和无线两种,也是计算机显示系统纵横坐标定位的指示器,因形似老鼠而得名"鼠标"(港台作滑鼠)。

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>鼠标悬停效果</title>

    <style type="text/css">

        *{

            margin: 0

            padding: 0

        }

        body{

            background-color: #000

        }

        a{

            width: 200px

            height: 50px

            display: block

            text-align: center

            line-height: 50px

            text-decoration: none

            position: absolute

            top: 50%

            left: 50%

            transform: translate(-50%,-50%)

            font-size: 24px

            font-weight: bold

            color: white

            border: 1px solid white

            overflow: hidden

        }

        a::before{

            content: ""

            position: absolute

            top: 0

            left: -100%

            width: 100%

            height: 100%

            background-image: linear-gradient(60deg,transparent,rgba(146,148,248,.4),transparent)

            transition: all 0.5s

        }

        a:hover::before{

            left: 100%

        }

        a:hover{

            box-shadow: 0 2px 10px 8px rgba(146,148,248,.4)

        }

    </style>

</head>

<body>

    <a href="#">鼠标悬停效果</a>

</body>

</html>

CSS+HTML<悬停下划线效果>

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

    <style>

        body {

            display: flex

            height: 100vh

            justify-content: center

            align-items: center

        }

        ul {

            padding: 0

            margin: 0

            list-style-type: none

        }

        ul li{

            padding: 5px 0

        }

        ul li a {

            position: relative

            display: inline-block

            text-decoration: none

            color: #3a3a3a

            /* 转大写 */

            text-transform: uppercase

            padding: 4px 0

            transition: 0.5s

            font-weight: bold

        }

        ul li a::after {

            position: absolute

            content: ""

            width: 100%

            height: 3px

            top: 100%

            left: 0

            background: #347cdb

            transition: transform 0.5s

            transform: scaleX(0)

            transform-origin: right

        }

        ul li a:hover {

            color: #585858

            text-shadow: 0 0 10px #ccc

        }

        ul li a:hover::after {

            transform: scaleX(1)

            transform-origin: left

        }

    </style>

</head>

<body>

    <ul>

        <li><a href="#">home</a></li>

        <li><a href="#">archives</a></li>

        <li><a href="#">tags</a></li>

        <li><a href="#">categories</a></li>

        <li><a href="#">about</a></li>

    </ul>

</body>

</html>