<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.box {
width: 900px
background-color: #eee
border: 1px dashed #ccc
margin: 0 auto
}
.top {
height: 80px
}
.banner {
height: 120px
/*margin: 0 auto*/
margin: 5px auto
}
.main {
height: 500px
}
.footer {
height: 100px
/*margin: 0 auto
margin-top:5px*/
margin: 5px auto 0
}
</style>
</head>
<body>
<div class="top box">top</div>
<div class="banner box">banner</div>
<div class="main box"></div>
<div class="footer box"></div>
</body>
</html>
<!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>
鼠标悬停tip效果,是一个非常有用的功能,在页面布局受到局限的时候,我们不能往页面中添加过多的内容。而鼠标悬停tip效果,可以在鼠标移上去的时候有一个提示信息,我们可以将相关的信息放置在这
个tip中,不影响页面美观而又能很好的传达信息。
应用div
css布局,我们用CSS可以实现这样的效果吗?其实这很简单,我们可以新建一个span或div
,将之初始设置成:display:none,隐藏这一标签的内容。(关于display可以参考这里)当鼠标移上去
的时候,我们将此内容显示出来。然后对其进行定位。就达到了鼠标悬停tip效果。
鼠标悬停tip效果实例
CSS代码
a#tip
{position:relativeleft:30pxtop:30px}
a#tip:link
{text-decoration:nonecolor:#c00display:block}
a#tip:hover
{text-decoration:nonecolor:#000display:block}
a#tip
span
{display:none}
a#tip:hover
#tip_info
{
display:block
border:1px
dashed
#c00
background:#fff
padding:1px
position:absolute
top:0px
left:120px
}
鼠标悬停tip效果实例
XHTML代码
<a
id="tip"
href="http://www.zlbiz.com">【www.zlbiz.com】
<span
id="tip_info">
<img
src="http://www.zlbiz.com/skins/logo3.gif"
alt="www.zlbiz.com"
width="200"
height="90"
/>
</span>
</a>
查看鼠标悬停tip运行效果
<!DOCTYPE
html
PUBLIC
"-//W3C//DTD
XHTML
1.0
Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta
http-equiv="Content-Type"
content="text/html
charset=utf-8"
/>
<title>www.zlbiz.com</title>
<style
type="text/css">
body
{font:normal
14px
宋体}
a#tip
{position:relativeleft:30pxtop:30px}
a#tip:link
{text-decoration:nonecolor:#c00display:block}
a#tip:hover
{text-decoration:nonecolor:#000display:block}
a#tip
span
{display:none}
a#tip:hover
#tip_info
{
display:block
border:1px
dashed
#c00
background:#fff
padding:1px
position:absolute
top:0px
left:120px
}
</style>
</head>
<body>
<a
id="tip"
href="http://www.zlbiz.com">【www.zlbiz.com】
<span
id="tip_info"><img
src="http://www.zlbiz.com/skins/logo3.gif"
alt="www.zlbiz.com"
width="200"
height="90"
/></span>
</a>
</body>
</html>