常用前端代码整理

// 手机适配
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
// 弹性布局
display: flex;
flex-wrap: wrap;
justify-content: space-between;

// 字符串一行显示
.text_ellipsis{
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
关于文本的截取,解决方案有两种:                                                                             方案1:纯css                                                                                                                    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 6;
    overflow: hidden;                                                                                                   方案二:vue filter截取方案                                                                                             export default {
    ...
    filters : {
        lineClamp(value){
            return value.length > 200 ? value.slice(0, 200) + '...' : value
        }
    }
    ...
}  

// 圆形图标(带阴影)
.icon{
          width: 60px;
          height: 60px;
          background-repeat: no-repeat;
          background-position: center;
          background-size: 60px;
          padding: 10px;
          background-color: #fff;
          border-radius: 50% 50%;
          box-shadow: 2px 4px 4px #cccccc7a;
}

// 两个item一行的盒子效果
div.container
{
    width:30em;
    border:1em solid;
}
div.box
{
    box-sizing:border-box;
    -moz-box-sizing:border-box; /* Firefox */
    -webkit-box-sizing:border-box; /* Safari */
    width:50%;
    border:1em solid red;
    float:left;
}

// 文本左侧图标
.bg_icon {
    padding-left: 43px;
    background-size: 39px;
    background-repeat: no-repeat;
    background-position: left;
}

// 一行多item滚动效果
.container {
    display: flex;
    flex-wrap: nowrap;

    overflow-x: auto;
    overflow-y: hidden;
    overflow-scrolling: touch;
    white-space: nowrap;

    .item {

        margin-right: 20px;
        width: 280px; // 必须设置
        display: inline-block;
    }
}

// 隐藏滚动条
// 方法一:
::-webkit-scrollbar{
  display: none;
}

// 方法二:
::-webkit-scrollbar {
    width: 0px;
    height: 1px;
}
::-webkit-scrollbar-thumb {
    border-radius: 5px;
    -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background: rgba(0, 0, 0, 0.2);
}

// :last-child 选择器匹配属于其父元素的最后一个子元素的每个元素。
// p:last-child 等同于 p:nth-last-child(1)。
p:last-child
{ 
background:#ff0000;
}

// &是指找到符合条件的选择器进行设置
&.active{
          border-bottom: 8px solid #ff3371
        }
// 查找第一个对象
&:nth-child(1) {
        .body_rank {
            background-color: rgb(221, 123, 210);
        }
    }
// vue语法
// 根据条件绑定类名
:class="{'active':currentIndex === index}"

// 绑定方法
@switch="switchItem"
// 传入值的方法
methods: {
      switchItem (index) {
        this.$emit('switch', index)
      }
    }
// 绑定行为
@click="switchItem(index)"

// vue绑定style
:style="`background-image:url(${leagueTableModel.type === 1 ? leagueTableModel.imgUrl : 'https://img3.doubanio.com/img/files/file-1508395738-0.jpg'})`

// 跳转
// 跳转页面
<router-link tag="div" to="/user/settings/logBind" class="">
</router-link>
// route/index.js
path: '/register', // 活动报名
          component: resolve => require(['@/pages/Home/subpages/register.vue'], resolve), // 报名页面
          children: [
            {
              path: 
              component:
            }
          ]
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 最近发现收藏夹的东西太多太乱了,就想者把平时常用的资源整理出来,与大家共享。 1、vue配套工具 vue.js中文...
    小母鸡叽叽叽阅读 2,418评论 3 72
  • css属性很多加上css3新增的就更多了,开发过程中难免有遗漏掉的,有时候又不想翻看繁琐的api文档,所以就把常用...
    小厨笔记阅读 313评论 0 13
  • 文字右端对齐 解决IE8不支持background-size问题 改变cursor 样式 路径必须是绝对路径,IE...
    zzj_alpaca阅读 406评论 0 1
  • 1、vue配套工具 vue.js中文文档 vue-routervue路由 vuexvue状态管理 vue-reso...
    iGiky阅读 315评论 0 0
  • 秋风起,树叶黄。当发白的老玉米归仓的时候,那长在墙头,挂在树梢的葫芦也发了白,收获时节到了。 葫芦藤蔓蹿起老高,在...
    碧潭止水阅读 895评论 0 1