CSS-实战-上传按钮美化

1、实现效果

实现效果

2、实现思路

(1) 创建丑陋的文件输入框


丑陋的文件输入框

(2)创建美化的DIV


美化后的div

(3)设置丑陋的输入框透明
(4)使用美化后的DIV遮挡默认输入框。

div 的父元素设置为相对定位,div元素使用绝对定位。


半透明效果

3、实现代码

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传按钮美化</title>
    <style type="text/css">
        .upload{
            width: 100px;
            height: 40px;
            position: relative;
            border:1px solid #ccc;
            background:#eee;
            color :#fff;
            text-shadow : none;
            box-shadow :1px 1px 3px rgba(0,0,0,.2)
            cursor:pointer;
        }
     
        .upload{
            width: 84px;
            height: 28px;
            position: relative;
            border:1px solid #00b7ee;
            background:#00b7ee
        }
     
        .txt {
            float: left;
            position: absolute;
            left: 0px;
            top: 0px;
            width: 84px;
            height: 28px;
            text-align: center;
            line-height: 28px;
            color : white;
         
        }
        .file{
            width: 84px;
            height: 28px;
            opacity:0.0;filter:alpha(opacity=0);
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="upload">
        <div class="txt">上传图片</div>
        <input type="file" class="file" value="上传文件">
    </div>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,815评论 1 92
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,678评论 25 708
  • 在一回首间,才忽然发现,原来,我一生的种种努力,不过只为了周遭的人对我满意而已。为了搏得他人的称许与微笑,我战战兢...
    Alice王志荣阅读 183评论 0 0
  • ` 迫于现实生活拿穷困潦倒做要挟,自己不屈从,不妥协,便奋起反抗。 至于这一次,自己能坚持多久,在于自己缺钱的状态...
    杨丽冰阅读 364评论 0 1