CSS格式化、兼容及常用样式(switch开关记得收藏)

4 篇文章 0 订阅

内容介绍

  不经历项目的苦,哪能体会一像素一边框一阴影带来的痛(为了减少痛苦,建议收藏备用)

一、格式化
1、select格式化样式
/* select格式化样式: */
.select {
    border: 1px solid #C6CBD4;
    outline: none;
    text-shadow: none;
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
    -webkit-user-select: text;
    box-shadow: none;
}
2、button格式化样式
/* button格式化样式:  */
#searchBtn {
    width: 134px;
    height: 40px;
    font-weight: bold;
    background-color: #0FB273;
    cursor: pointer;
    color: #fff;
    outline: none;
    border: none;
    text-shadow: none;
    -webkit-appearance: none;
    -webkit-user-select: text;
    box-shadow: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
}
3、input去除边框
/* input去除边框: */
input {
    outline: none;
    border: 0;
}
4、selection去除下拉三角按钮
/* selection去除下拉三角按钮:  */
select {
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
}

select::-ms-expand {
    display: none;
}
5、textarea隐藏右下角拖动及滚动条
/* textarea隐藏右下角拖动及滚动条: */
#refuseTextarea {
    width: 680px;
    height: 160px;
    resize: none;
    text-indent: 10px;
    line-height: 20px;
    border-radius: 4px;
    padding: 5px 0;
    border: none;
    outline: none;
}

#refuseTextarea::placeholder {
    color: rgba(0, 0, 0, 0.25);
}

#refuseTextarea::-webkit-scrollbar {
    width: 0;
    display: none;
}
二、兼容
1、textarea滚动条——针对firefox浏览器
/* textarea滚动条——针对firefox浏览器 */
textarea {
    scrollbar-color: transparent transparent;
    scrollbar-track-color: transparent;
    -ms-scrollbar-track-color: transparent;
}
2、flex布局
/* flex布局 */
.flexBox {
    display: flex;
    display: -moz-flex;
    display: -o-flex;
    display: -webkit-flex;
    display: -ms-flex;
}
三、常用样式
1、不重复百分百背景图居中
/* 不重复百分百背景图居中 */
.bgCover {
    background-position: center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
}
2、文本两端对齐
/* 文本两端对齐: */
.text {
    text-align-last: justify;
    text-align: justify;
    text-justify: distribute-all-lines;
    /* 兼容ie */
}
3、文本不被选中(可禁止移动端长按选中复制)
/* 文本不被选中(可禁止移动端长按选中复制):  */
body {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
4、防止滚动条导致页面晃动
/* 防止滚动条导致页面晃动: */
html {
    overflow-y: scroll;
}

:root {
    overflow-x: auto;
    overflow-y: hidden;
}

:root body {
    position: absolute;
}

body {
    width: 100vw;
    overflow: hidden;
}
5、按钮轮廓
/* 按钮轮廓: */
.button {
    box-shadow: inset -1px 0px 1px 1px #333;
}
6、table表格多行居中
/* table表格多行居中: */
.missionTable .limitCell {
    line-height: 20px;
    display: table-cell;
    vertical-align: middle;
}
7、文本换行
.textWrap {
    /* 自动换行(包括网址): */
    word-wrap: break-word;
    word-break: break-all;
    white-space: normal;
    /* 单行文本溢出省略号: */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
8、复选框不同状态背景图
/* 复选框不同状态背景图: */
.checkList>input {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    position: relative;
}

.checkList>input::after {
    content: "";
    width: 16px;
    height: 16px;
    position: absolute;
    background-repeat: no-repeat;
    background-size: 16px 16px;
    background-position: center;
}

.checkList>input:checked::after {
    background-image: url('../images/selected.png');
}

.checkList>input:disabled::after {
    background-image: url('../images/choose.png');
}
四、switch开关
1、mui-switch.css
  1.1 效果图

switch开关截图


  1.2 HTML代码
<label><input class="mui-switch mui-switch-animbg" type="checkbox">文字</label>
  1.3 CSS代码
.mui-switch {
    width: 52px;
    height: 31px;
    position: relative;
    border: 1px solid #dfdfdf;
    background-color: #fdfdfd;
    box-shadow: #dfdfdf 0 0 0 0 inset;
    border-radius: 20px;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    background-clip: content-box;
    display: inline-block;
    -webkit-appearance: none;
    user-select: none;
    outline: none;
}

.mui-switch:before {
    content: '';
    width: 29px;
    height: 29px;
    position: absolute;
    top: 0px;
    left: 0;
    border-radius: 20px;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.mui-switch:checked {
    border-color: #64bd63;
    box-shadow: #64bd63 0 0 0 16px inset;
    background-color: #64bd63;
}

.mui-switch:checked:before {
    left: 21px;
}

.mui-switch.mui-switch-animbg {
    transition: background-color ease 0.4s;
}

.mui-switch.mui-switch-animbg:before {
    transition: left 0.3s;
}

.mui-switch.mui-switch-animbg:checked {
    box-shadow: #dfdfdf 0 0 0 0 inset;
    background-color: #64bd63;
    transition: border-color 0.4s, background-color ease 0.4s;
}

.mui-switch.mui-switch-animbg:checked:before {
    transition: left 0.3s;
}

.mui-switch.mui-switch-anim {
    transition: border cubic-bezier(0, 0, 0, 1) 0.4s, box-shadow cubic-bezier(0, 0, 0, 1) 0.4s;
}

.mui-switch.mui-switch-anim:before {
    transition: left 0.3s;
}

.mui-switch.mui-switch-anim:checked {
    box-shadow: #64bd63 0 0 0 16px inset;
    background-color: #64bd63;
    transition: border ease 0.4s, box-shadow ease 0.4s, background-color ease 1.2s;
}

.mui-switch.mui-switch-anim:checked:before {
    transition: left 0.3s;
}
2、switch.css
  2.1 效果图

switch开关截图


  2.2 HTML代码
<input class="switch switch-anim containerPagingStatusChild" status="0" type="checkbox" />
  2.3 CSS代码
.switch {
    width: 57px;
    height: 28px;
    position: relative;
    border: 1px solid #dfdfdf;
    background-color: #fdfdfd;
    box-shadow: #dfdfdf 0 0 0 0 inset;
    border-radius: 20px;
    background-clip: content-box;
    display: inline-block;
    -webkit-appearance: none;
    user-select: none;
    outline: none;
    cursor: pointer;
}

.switch:before {
    content: '';
    width: 26px;
    height: 26px;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 20px;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.switch:checked {
    border-color: #4B74FF;
    box-shadow: #4B74FF 0 0 0 16px inset;
    background-color: #4B74FF;
}

.switch:checked:before {
    left: 30px;
}

.switch.switch-anim {
    transition: border cubic-bezier(0, 0, 0, 1) 0.4s, box-shadow cubic-bezier(0, 0, 0, 1) 0.4s;
}

.switch.switch-anim:before {
    transition: left 0.3s;
}

.switch.switch-anim:checked {
    box-shadow: #4B74FF 0 0 0 16px inset;
    background-color: #4B74FF;
    transition: border ease 0.4s, box-shadow ease 0.4s, background-color ease 1.2s;
}

.switch.switch-anim:checked:before {
    transition: left 0.3s;
}

标签:CSS,格式化样式,兼容样式,常用样式,switch开关


更多演示案例,查看 案例演示


欢迎评论留言!

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

人间小美味695

您的鼓励是我创作的动力,感谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值