关于上一篇鼠标移到按钮时的“按下”效果的三种方法
2016-07-19 23:47
363 查看
上一篇博文中,关于按钮按下的效果回过头研究了下,总结了如下三种方法,只写出关键样式:
1、相对定位input.button{
position:relative; //用相对定位
}
input.button:hover{
top:2px;//鼠标移动到此top增加2px
}
2、主要利用外边距这个属性,鼠标移动到按钮位置时,按钮上外边距增加2px,下外边距减少2px(相当于走出去2px又退回来2px),就可以达到按下效果,如果只是单独写margin-top:2px;鼠标移动到按钮时,后面的按钮也会跟着一起向下移动。
input.button{
margin:2px; //先设置外边距为2px
}
input.button:hover{
margin-top:4px;
margin-bottom:0px;
}
3、利用内边距,设置按钮的容器(btns)的内边距,跟上一种相对,上一个是从按钮本身出发,现在是从它的容器开始,相当于把按钮推下去0.2cm又拉回来0.2cm。
<span style="font-family:monospace;color:#000000;font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">#btns{padding: 0.3cm 0.5cm;} //上下内边距都是0.3cm,左右内边距都是0.5cm</span>
#btns:hover{
padding-top: 0.4cm;
padding-bottom:0.2cm;
}
哪里没讲清楚的请联系博主,一起探讨!
1、相对定位input.button{
position:relative; //用相对定位
}
input.button:hover{
top:2px;//鼠标移动到此top增加2px
}
2、主要利用外边距这个属性,鼠标移动到按钮位置时,按钮上外边距增加2px,下外边距减少2px(相当于走出去2px又退回来2px),就可以达到按下效果,如果只是单独写margin-top:2px;鼠标移动到按钮时,后面的按钮也会跟着一起向下移动。
input.button{
margin:2px; //先设置外边距为2px
}
input.button:hover{
margin-top:4px;
margin-bottom:0px;
}
3、利用内边距,设置按钮的容器(btns)的内边距,跟上一种相对,上一个是从按钮本身出发,现在是从它的容器开始,相当于把按钮推下去0.2cm又拉回来0.2cm。
<span style="font-family:monospace;color:#000000;font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">#btns{padding: 0.3cm 0.5cm;} //上下内边距都是0.3cm,左右内边距都是0.5cm</span>
#btns:hover{
padding-top: 0.4cm;
padding-bottom:0.2cm;
}
哪里没讲清楚的请联系博主,一起探讨!
相关文章推荐
- Web布局连载——两栏固定布局(五)
- [div+css]晒晒最新制作专题推广页模板
- 微软无线镭射简报鲨8000激光笔记本鼠标 - (2)
- 在Windows 8.1的IE 11中屏蔽双击放大功能
- 盒子模型
- CSS选择器
- CSS样式优先权
- HTML5调用摄像头实例
- Powershell 创建炫丽美观的Html报表
- [css] line-height 百分比单位和数值单位的区别
- css如何搞正方形
- Apple官网研究之使用Justify布局导航
- 关于前端的思考与感悟
- rem : web app适配的秘密武器
- jquery高级应用之Deferred对象
- 又被事件冒泡坑了一把,这次要彻底弄懂浏览器的事件流