当前位置:   article > 正文

表单元素的css样式,自适应屏幕_css + 自适应 + 表单

css + 自适应 + 表单

经常写表单样式,这边记录一下最近写的css样式。效果是:label固定长度,input框为100%。

<form class="fe-form required colon">
    <div class="form-group">
        <label class="form-label">姓名</label>
        <input type="text" class="fe-input" placeholder="请输入姓名">
    </div>

    <div class="form-group" >
        <label class="form-label">something to drink?</label>
        <select class="fe-select">
            <option value=" ">something to drink</option>
            <option value="apple">coffee</option>
            <option value="banana">tea</option>
            <option value="orange">Coca Cola</option>
            <option value="orange">橙汁儿</option>
        </select>
    </div>  
    <div class="form-group">
        <label class="form-label">详细描述</label>
        <textarea class="fe-input success" placeholder="请详细描述"></textarea>
    </div>
</form>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

less文件:

@error-color: #ff0000;
@waring-color: #C8C365;
@success-color: #3c763d;
.fe-form {
    width: 100%;
    &.colon {
        .form-label:after {
            content: ":";
        }
    }
    &.required, &.required-before {
        .form-label:before {
            content: "*";
            color: #ff0000;
        }
    }
    &.required-after {
        .form-label:after {
            content: "*";
            color: #ff0000;
        }
    }
    .form-group {
        margin-bottom: 15px;
        height: 37px;
        position: relative;
        box-sizing: border-box;
        padding-left: 120px;
        .form-label {
            text-align: left;
            font-weight: normal;
            position: absolute;
            top: 5px;
            left: 0;
        }
        input, select, textarea {
            width: 100%;
            display: block;
            padding: 6px 12px;
            font-size: 12px;
            line-height: 1.42857143;
            color: #555555;
            background-color: #ffffff;
            background-image: none;
            border: 1px solid #cccccc;
            border-radius: 4px;
            box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
            transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
        }
        &.size-xs {
            padding-left: 80px;
        }
        &.size-s {
            padding-left: 100px;
        }
        &.size-m {
            padding-left: 120px;
        }
        &.size-l {
            padding-left: 140px;
        }
        &.size-xl {
            padding-left: 160px;
        }
    }
    .fe-input {
        font-family: inherit;
        font-size: inherit;
        &[type="search"] {
            -webkit-appearance: none;
        }
        color: #555555;
        background-color: #ffffff;
        background-image: none;
        border: 1px solid #cccccc;
        border-radius: 4px;
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
        box-sizing: border-box;
        &:focus {
            border-color: #b597c7;
            outline: 0;
            box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(181, 151, 199, 0.6);
        }
        &.warning {
            border-color: @waring-color;
            box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
            &:focus {
                border-color: @waring-color;
                box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #c0a16b;
            }
        }
        &.success {
            border-color: @success-color;
            box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
            &:focus {
                border-color: @success-color;
                box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #67b168;
            }
        }
        &.error {
            border-color: @error-color;
            box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
            &:focus {
                border-color: @error-color;
                box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ff6666;
            }
        }
        &[disabled], &[readonly] {
            cursor: not-allowed;
            background-color: #eeeeee;
            opacity: 1;
        }
    }
    .fe-select {
        display: block;
        width: 100%;
        height: 31px;
        padding: 6px 12px;
        font-size: 12px;
        margin: 0;
        line-height: 1.42857143;
        color: #555555;
        background-color: #ffffff;
        background-image: none;
        border: 1px solid #cccccc;
        border-radius: 4px;
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
        transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
        text-transform: none;
        &:focus {
            border-color: #b597c7;
            outline: 0;
            box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(181, 151, 199, 0.6);
        }
        &::-moz-placeholder {
            color: #999999;
            opacity: 1;
        }
        &:-ms-input-placeholder, &::-webkit-input-placeholder {
            color: #999999;
        }
        &[disabled], &[readonly] {
            cursor: not-allowed;
            background-color: #eeeeee;
            opacity: 1;
        }
        &[multiple], &[size] {
            height: auto;
        }
        &.input-sm, .form-group-sm {
            height: 28px;
            line-height: 28px;
        }
        &.input-lg, .form-group-lg {
            height: 42px;
            line-height: 42px;
        }
        &.warning {
            border-color: @waring-color;
            box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
            &:focus {
                border-color: @waring-color;
                box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #c0a16b;
            }
        }
        &.success {
            border-color: @success-color;
            box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
            &:focus {
                border-color: @success-color;
                box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #67b168;
            }
        }
        &.error {
            border-color: @error-color;
            box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
            &:focus {
                border-color: @error-color;
                box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #ff6666;
            }
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/812292
推荐阅读
相关标签
  

闽ICP备14008679号