实现代码如下:
<divclass="wrap">
<divclass="img"></div>
<divclass="notice">1</div>
</div>
<divclass="wrap">
<divclass="img"></div>
<divclass="notice">12</div>
</div>
<divclass="wrap">
<divclass="img"></div>
<divclass="notice">13</div>
</div>
<style>
.wrap{
width:50px
margin-bottom:10px
position:relative
}
.img{
width:50px
height:50px
border:1pxsolid#000
}
.notice{
width:20px
height:20px
line-height:20px
font-size:10px
color:#fff
text-align:center
background-color:#f00
border-radius:50%
position:absolute
right:-10px
top:-10px
}
</style>
扩展资料:注意事项
主要用到position定位,CSSposition属性用于指定一个元素在文档中的定位方式。top、right、bottom、left 属性则决定了该元素的最终位置。
static是position的默认值。
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>CSS-position-static</title>
<linkrel="stylesheet"href="https://cdn.bootcss.com/normalize/8.0.0/normalize.css">
<style>
.container{
background-color:#868686
width:100%
height:300px
}
.content{
background-color:yellow
width:100px
height:100px
position:static
left:10px/*这个left没有起作用*/
}
</style>
</head>
<body>
<divclass="container">
<divclass="content">
</div>
</div>
</body>
</html>
<html><head>
<title>网页特效-文本特效-渐显的文字提示效果</title>
<FCK:meta http-equiv="content-Type" content="text/htmlcharset=gb2312" />
<!--把下面代码加到<head>与</head>之间-->
<style type="text/css">
.lookMe{
float:left
margin-right:10px
padding:5px
width:90px
color:#0099FF
cursor:pointer
background:#FFFADC
border:1px solid #CC6600
}
.lookMe span{
display:none
position:absolute
padding:5px
width:200px
color:#CC3300
background:#FFFADC
border:1px solid #CC6600
filter:alpha(opacity=0)
}
</style>
</head>
<body>
<!--把下面代码加到<body>与</body>之间-->
<div onmouseover_fckprotectedatt="%20onmouseover%3D%22lookMe(this)%3B%22" class="lookMe" onmousemove_fckprotectedatt="%20onmousemove%3D%22mouseMove(event)%3B%22">闷战120分钟点球战4:2 西班牙破魔咒淘汰意大利
<span>1、雅虎体育讯 北京时间6月23日,欧洲足球锦标赛在瑞士奥地利继续进行,在一场四分之一决赛中,西班牙队迎来了上届世界杯冠军意大利队,90分钟与加时赛双方均一球未进,在最终的点球大战中,西班牙4:2击败了对手,昂首挺进四强。</span>
</div>
<div onmouseover_fckprotectedatt="%20onmouseover%3D%22lookMe(this)%3B%22" class="lookMe" onmousemove_fckprotectedatt="%20onmousemove%3D%22mouseMove(event)%3B%22">闷战120分钟点球战4:2 西班牙破魔咒淘汰意大利
<span>2、在一场四分之一决赛中……</span>
</div>
<div onmouseover_fckprotectedatt="%20onmouseover%3D%22lookMe(this)%3B%22" class="lookMe" onmousemove_fckprotectedatt="%20onmousemove%3D%22mouseMove(event)%3B%22">闷战120分钟点球战4:2 西班牙破魔咒淘汰意大利
<span>3、欧洲足球锦标赛在瑞士奥地利继续进行,在一场四分之一决赛中,西班牙队迎来了上届世界杯冠军意大利队,90分钟与加时赛双方均一球未进,在最终的点球大战中,西班牙4:2击败了对手,昂首挺进四强。</span>
</div>
<script>
var span,timer1
function lookMe(thisTag){
span = thisTag.getElementsByTagName('span')[0]
span.style.display = 'block'
span.filters[0].opacity=0
timer1=setInterval("showme()",10)
thisTag.onmouseout = function(){
span.style.display = 'none'
}
}
function showme()
{
if(span.filters[0].opacity==80){clearInterval(timer1)}
span.filters[0].opacity++
}
function mouseMove(event){
var xx=event.clientX + 5
var yy=event.clientY + 10
var obj = event.srcElement ? event.srcElement : event.target
var span=obj.getElementsByTagName("span")[0]
span.style.left = xx + 'px'
span.style.top = yy + 'px'
}
</script>
</body>
</html>
用获得焦点onfocus和失去焦点onblur事件
<html><head>
<script>
function show(){
var test=document.getElementById("uname").value
if(test==null || test==""){
document.getElementById("abc").style.display=''
}else{
document.getElementById("abc").style.display='none'
}
}
function hide(){
document.getElementById("abc").style.display='none'
}
</script>
</head>
<body>
<input id="uname" type="text" onblur="show()" onfocus="hide()"/><span id="abc">请输入名称</span>
</body>
</html>