文本框(input)添加提示图标与修饰效果

转载自:
http://www.codebit.cn/pub/html/xhtml_css/tip/input_background_image/

为你的文本框加一个说明用途的小图标

input.txtInput {
background: fff;
background-repeat: no-repeat;
background-position: 2px center;
border:1px solid 999;
padding:2px 2px 2px 20px;
}
input.searchInput {background-image: url(search.gif);}
input.commentInput {background-image: url(comments.gif);}


上面的代码中 input.txtInput 定义了文本框中有小图标的通用样式,其中 padding 的第四个值是定义文字内容从 20 象素处开始,原因是本文的图片是 16 象素大小,文字四周有 2 象素的边距。具体到实际应用,需要根据你的图片大小决定。

然后,我们又定义了 searchInput  和 commentInput  两个文本框样式,分别设置了2个不同的小图标。这样,我们在设置文本框的 class 时可以这样写:

<p>
<label for="keyword">搜索:</label>
<input type="text" name="keyword" id="keyword" class="txtInput searchInput" />
</p>
<p>
<label for="comment">评论:</label>
<input type="text" name="comment" id="comment" class="txtInput commentInput" />
</p> 



为你的文本框加一个效果柔和的边框

input.borderInput {
background-image: url(border.gif);;
background-repeat: no-repeat;
background-position: left top;
border:1px solid d5dee9;
padding:3px;
} 


上面的代码设置了一个背景图,并且左上对齐,当然,我们这个图片通常要宽一些、高一些,然后设置一个和渐变颜色近似的 border 。是的,一个效果柔和的边框实现了。



border.gif:看不太清楚^_^

//----------------------------------

//--------------------------------

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值