CSS应用案例

表单美化

  • 如果body不能直接撑起高,给html标签添加height:100%

  • filter是滤镜,针对的元素里面的所有内容,默认是0px

  • 效果使用background-clip: content-box;,同时设置padding值.clip:裁切

    效果

  • 使用定位剧中的方法:leftmargin配合使用。

  • background: linear-gradient(red 10%,red 20%,green 20%,green 40%,blue 40%);
    background: linear-gradient(transparent 0%,transparent 10%, black 10%,black 11%,transparent 11%);

.father{
display:flex;
}
.son{
            flex:1;
}
            flex: 1;
            /*

            flex决定了宽度

            根据当前富裕宽度[剩余可利用空间]/当前 fiex总和。
            */
  • outline是轮廓。像input标签的点击浅蓝色就可以通过设置outline清除掉

//获得焦点之后,执行CSS
    <style>
        .input1{
            outline: none;
            border: none;
            height: 50px;
            border-bottom: 1px solid black;
        }

        .input1:focus{
            border-bottom-color: red;
        }
        
        .input1::-webkit-input-placeholder{
            transition: .5s;
        }
        .input1:focus::-webkit-input-placeholder{
            transform: scale(0.7) translateY(-10px);
            transform-origin: left top;
        }
    </style>
</head>
<body>
<input type="text" class="input1" placeholder="请输入账号" >
</body>

详尽代码

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表单美化2</title>
    <style>
        *{
            margin: 0px;
            top: 0px;
        }
        html{
            height: 100%;
        }
        body{
            height: 100%;
        }
        .mask{
            width: 100%;
            height: 100%;
            background-image: url("img/bg.jpg");
            background-size: cover;
            filter: blur(5px);/*这个是添加的滤镜*/
        }
        .drog{
            position: absolute;
            left: 0px;
            top: 0px;
            width: 640px;
            height: 620px;
            border: 1px solid white;
            background-color: rgba(255,255,255,0.8);
            background-clip: content-box;/*规定背景图的绘制区域*/
            padding: 10px;
            left: 50%;
            top: 50%;
            margin-left: -320px;
            margin-top: -310px;
            border-radius: 10px;
        }
        .title{
            text-align: center;
            font-size: 28px;
            margin: 24px 0px;
            display: flex;
        }

        .title .title_name{
            padding: 0px 10px;
        }
        .title .line{
            background: linear-gradient(transparent 49%,black 49%,black 50%,transparent 50%);
            flex:1;
        }

        table{
            width: 100%;
        }
        .td_left{
            text-align: right;
            width: 150px;
        }

        .userInput{
            outline: none;
            height: 40px;
            border:none;
            border-bottom: 1px solid black;
            background-color: rgba(255,255,255,0);
        }
        .userInput:focus{
            border-bottom-color: red;
        }

        .userInput::-webkit-input-placeholder{
            transition: .5s;
        }
        .userInput:focus::-webkit-input-placeholder{
            transform: scale(0.7) translateY(-10px);
            transform-origin: left top;
        }

        /*单选框修改*/
        .chooseGender input{
            display: none;
        }
        .chooseGender label{
            width: 8px;
            height: 8px;
            margin: 1px;
            border: 1px solid #000;
            display: inline-block;
            border-radius: 50%;
            position: relative;
        }

        .chooseGender input:checked +label{
            border-color: #888;
        }
        .chooseGender input:checked+label:before{
            content: '';
            width: 4px;
            height: 4px;
            background-color: red;
            display: inline-block;
            position: absolute;
            border-radius: 50%;
            left: 2px;
            top: 2px;
        }
        /*单选框修改结束*/


        /*多选框修改*/
        .chooseGreens input{
            display: none;
        }
        .chooseGreens label{
            width: 9px;
            height: 9px;
            margin: 1px 1px 0px 1px;
            border: 1px solid dimgrey;
            display: inline-block;
        }
        .chooseGreens input:checked+label{
            border-color: #000;
            position: relative;
        }
        .chooseGreens input:checked +label:before{
            content: '';
            width: 2px;
            height: 7px;
            background-color: red;
            display: inline-block;
            position: absolute;
            transform: rotate(-37deg);
            top: 1px;
            left: 2px;
        }
        .chooseGreens input:checked +label:after{
            content: '';
            width: 2px;
            height: 7px;
            background-color: red;
            display: inline-block;
            position: absolute;
            transform: rotate(29deg);
            top: 1px;
            left: 5px;
        }
        /*单选框修改结束*/


        /*开关效果开始*/
        .addressHidden #addHidd{
            display: none;
        }
        .addressHidden label{
            width: 40px;
            height: 20px;
            border: 1px solid #888;
            display: inline-block;
            border-radius: 15px;
        }
        .addressHidden label span{
            width: 20px;
            height: 20px;
            display: inline-block;
            border-radius: 15px;
            box-shadow: 1px 1px 1px  #ccc;
            background-color: white;
            transition:all  0.5s;

        }
        .addressHidden #addHidd:checked+label{
            background-color: greenyellow;
        }
        .addressHidden #addHidd:checked+label span{
            transform: translateX(20px);
        }
        /*开关效果结束*/

        /*
        开关效果带文字
        */

        .shareToNet #shareNet{
            display: none;
        }
        .shareToNet label{
            display: inline-block;
            width: 40px;
            height: 20px;
            border: 1px solid #888;
            border-radius: 15px;
            transition: 0.3s;
        }
        .shareToNet label .move{
            display: block;
            width: 20px;
            height: 20px;
            box-shadow: 1px 1px 1px #ccc;
            border-radius: 50%;
            background: white;
            transition: 0.3s;
            overflow: hidden;
        }

        .shareToNet #shareNet:checked+label{
            background-color: greenyellow;
        }

        .shareToNet input:checked+label .move{
            transform: translateX(20px);
            box-shadow: none;
        }

        em{
            font-size: 12px;
            font-style: normal;
            float: left;
            width: 50%;
        }
        .shareToNet input:checked+label .move span{
            transform: translateX(-20px);

        }
       .shareToNet .move span{
            width: 40px;
            display: block;
            height: 20px;
            text-align: center;
            transition: .3s;
            /*transform: translateX(-20px);*/
        }

    </style>
</head>
<body>
<div class="mask"></div>

<div class="drog">
    <h2 class="title">
        <span class="line"></span>
        <span class="title_name">用户注册</span>
        <span class="line"></span>
    </h2>

    <table>
        <tbody>
        <tr>
            <td class="td_left">姓名:</td>
            <td><input type="text" placeholder="请输入姓名" class="userInput"></td>
        </tr>

        <tr>
            <td class="td_left">密码:</td>
            <td><input type="text" placeholder="请输入密码" class="userInput"></td>
        </tr>

        <tr>
            <td class="td_left">确认密码:</td>
            <td><input type="text" placeholder="请确认密码" class="userInput"></td>
        </tr>

        <tr>
            <td class="td_left">性别选择:</td>
            <td class="chooseGender">
                <input type="radio" name="gender" id="chooseMan">
                <label for="chooseMan"></label>男
                <input type="radio" name="gender" id="chooseGirl">
                <label for="chooseGirl"></label>女
            </td>
        </tr>

        <tr>
            <td class="td_left">喜爱的菜系:</td>
            <td class="chooseGreens">
                <input type="checkbox" name="greens" id="food_z">
                <label for="food_z"></label>浙菜
                <input type="checkbox" name="greens" id="food_x">
                <label for="food_x"></label>湘菜
                <input type="checkbox" name="greens" id="food_y">
                <label for="food_y"></label>粤菜
                <input type="checkbox" name="greens" id="food_j">
                <label for="food_j"></label>京菜
                <input type="checkbox" name="greens" id="food_s">
                <label for="food_s"></label>苏菜
            </td>
        </tr>

        <tr>
            <td class="td_left">个人简介:</td>
            <td>
                <textarea cols="30" rows="10"></textarea>

            </td>
        </tr>

        <tr>
            <td class="td_left">地址匿名:</td>
            <td class="addressHidden">
                <input type="checkbox" id="addHidd">
                <label for="addHidd">
                    <span></span>
                </label>
            </td>
        </tr>


        <tr>
            <td class="td_left">分享到社交网络:</td>
            <td class="shareToNet">
                <input type="checkbox" id="shareNet">
                <label for="shareNet">
                    <span class="move">
                        <span>
                            <em>on</em>
                            <em>off</em>
                        </span>
                    </span>
                </label>
            </td>
        </tr>

        <tr>
            <td class="td_left"></td>
            <td>
                <input type="submit">
                <input type="reset">
            </td>
        </tr>

        </tbody>
    </table>
</div>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、垂直对齐 如果你用CSS,则你会有困惑:我该怎么垂直对齐容器中的元素?现在,利用CSS3的Transform,...
    kiddings阅读 3,199评论 0 11
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,796评论 1 92
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,333评论 0 11
  • 这篇文字里我会介绍50 个便于使用的 CSS2/CSS3 代码片段给所有的WEB专业人员. 选择IDE开发环境来存...
    JamHsiao_aaa4阅读 1,269评论 0 3
  • “你怎么那么慢,块点!”“知道了!后妈真是不好(小声)”“你说什么?”“没,没什么”“哼,你最好给我老实点,今天学...
    cptbtptpbc阅读 208评论 0 0