css文字定时消失

html-css020

css文字定时消失,第1张

这是一款很酷的带定时消失功能的css3消息提示框插件。

HTML

html结构非常简单:用一个wrapper div作为包裹容器,里面放一个用于显示信息的p标签和一个用来做进度条的div。

Your settings have been saved successfully!

为了给包裹div设置不同的颜色,给它设置两个class:tn-box和tn-box-color-1。

CSS

.tn-box {

width: 360px

position: relative

margin: 0 auto 20px auto

padding: 25px 15px

text-align: left

border-radius: 5px

box-shadow:

0 1px 1px rgba(0,0,0,0.1),

inset 0 1px 0 rgba(255,255,255,0.6)

opacity: 0

cursor: default

display: none

}

.tn-box-color-1{

background: #ffe691

border: 1px solid #f6db7b

}

设置包裹div的初始dispaly:none,并给设置它的透明度为0。

进度条的样式如下:

.tn-progress {

width: 0

height: 4px

background: rgba(255,255,255,0.3)

position: absolute

bottom: 5px

left: 2%

border-radius: 3px

box-shadow:

inset 0 1px 1px rgba(0,0,0,0.05),

0 -1px 0 rgba(255,255,255,0.6)

}

动画开始前,进度条的宽度为0。

在demo中,使用一个checkbox来作为按钮触发消息提示框动画。

input.fire-check:checked ~ section .tn-box {

display: block

animation: fadeOut 5s linear forwards

}

input.fire-check:checked ~ section .tn-box .tn-progress {

animation: runProgress 4s linear forwards 0.5s

}

因为按钮的动作发生在消息提示框之前,所以可以使用一般通用选择器来完成按钮操作。

如果你想使用javascript来完成按钮动作,你可以像下面这样写样式:

.tn-box.tn-box-active {

display: block

animation: fadeOut 5s linear forwards

}

.tn-box.tn-box-active .tn-progress {

animation: runProgress 4s linear forwards 0.5s

}

tn-box-active是在按钮按下时被加到tn-box div中的class。

下面是消息框淡入淡出动画效果:

@keyframes fadeOut {

0% { opacity: 0}

10% { opacity: 1}

90% { opacity: 1transform: translateY(0px)}

99% { opacity: 0transform: translateY(-30px)}

100% { opacity: 0}

}

下面是进度条的动画效果:

@keyframes runProgress {

0% { width: 0%background: rgba(255,255,255,0.3)}

100% { width: 96%background: rgba(255,255,255,1)}

}

我们使它运动到进度条宽度的96%,颜色上使用RGBA。

css 特殊input样式,参考如下:

输入框景背景透明:

<input style="background:transparentborder:1px solid #ffffff">

鼠标划过输入框,输入框背景色变色:

<INPUT value="Type here" NAME="user_pass" TYPE="text" SIZE="29" onmouseover="this.style.borderColor='black'this.style.backgroundColor='plum'"

style="width: 106 height: 21" 

onmouseout="this.style.borderColor='black'this.style.backgroundColor='#ffffff'" style="border-width:1pxborder-color=black">

输入字时输入框边框闪烁(边框为小方型):

<Script Language="javascript">

function borderColor(){

if(self['oText'].style.borderColor=='red'){

self['oText'].style.borderColor = 'yellow'

}else{

self['oText'].style.borderColor = 'red'

}

oTime = setTimeout('borderColor()',400)

}

</Script>

<input type="text" id="oText" style="border:5px dotted redcolor:red" onfocus="borderColor(this)" onblur="clearTimeout(oTime)">

输入字时输入框边框闪烁(边框为虚线):

<style>

#oText{border:1px dotted #ff0000ryo:expression(onfocus=function light (){with(document.all.oText){style.borderColor=(style.borderColor=="#ffee00"?"#ff0000":"#ffee00")timer=setTimeout(light,500)}},onblur=function(){this.style.borderColor="#ff0000"clearTimeout(timer)})}

</style>

<input type="text" id="oText">

自动横向廷伸的输入框:

<input type="text" style="huerreson:expression(this.width=this.scrollWidth)" value="abcdefghijk">

自动向下廷伸的文本框:

<textarea name="content" rows="6" cols="80" onpropertychange="if(this.scrollHeight>80) this.style.posHeight=this.scrollHeight+5">输入几个回车试试</textarea>

只有下划线的文本框:

<input style="border:0border-bottom:1 solid blackbackground:">

软件序列号式的输入框:

<script for="T" event="onkeyup">

if(value.length==3)document.all[event.srcElement.sourceIndex+1].select()

</script>

<input name="T" size="5" maxlength="3">—<input name="T" size="5" maxlength="3">—<input name="T" size="5" maxlength="3">—<input name="T" size="5" maxlength="3">—<input name="T" size="5" maxlength="3">—<input name="T7" size="5" maxlength="3">

可以使用hover 比如有个父盒子暂且给个类名为f 有个子盒子暂且给个类名为c 给c一个disiplay:none;让其隐藏 然后.f:hover.c {disiplay:block} 这样当鼠标悬停父盒子的时候 子盒子就会显示出来 另外 需要注意hover和.c之间没有空格