HTML5 & MUI 界面样式

什么?这是要做前端的节奏吗?只要公司有需要,我分分钟变身、前端、美工、UI、交互、后端、数据库管理员......快速学习、快速响应,快速适应。公司需要我干啥,我就干啥,而我存在于公司的意义就是利用所学的东西帮公司解决问题......事实上,如果让一个人来搞定整个项目包括移动端、PC端等等,那你还不是被逼得啥都会。

垂直居中+自动换行

样式效果如下所示,当文字没有超出一行时,显示如“备注信息”,当文字超出一行时,显示如“维修地点”

HTML代码如下:

                    <div class="mui-input-row multi-line">
                        <div class="box label-right">
                            <div class="div-leftauto">维修地点</div>
                            <div class="wrap">广东省深圳市南山区西丽街道桃源路1001号</div>
                        </div>
                    </div>

css样式如下:

/*不固定高宽div垂直居中的方法:其它页用*/
.box {width: 100%;height: 40px;border: 1px solid #FFF;display: table;margin-right:5px;}
.wrap{display: table-cell; vertical-align: middle; width: 100%;padding: 6px 0px;line-height: 26px;word-wrap: break-word; word-break: break-all;}    
.mui-input-row .div-leftauto{width:110px; display: inline-block;vertical-align: middle;margin-left:5px;/*padding-top: 8px;vertical-align:top;*/}
.mui-input-row.multi-line{height: auto;}

需要注意的是代码:word-wrap: break-word; word-break: break-all;

如果不加上这代码的话,当<div class="wrap">中的文字全部是数字或者英文的时候将不会出现自动换行。

 文字超出行显示省略号

如下图所示:

代码:

 <div style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"> 是文字随便几行我是文字随便几行我是文字随便几行我是文字随便几行我是文字随便几行我是文字随便</div>

这里只支持单行省略号,如果是多行呢?

    <div style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;">
        是文字随便几行我是文字随便几行我是文字随便几行我是文字随便几行我是文字随便几行我是文字随便几行是文字随便几行我是文字随便几行我是文字随便几行我是文字随便几行我是文字
随便几行我是文字随便几行是文字随便几行我是文字随便几行我是文字随便几行我是文字随便几行我是文字随便几行我是文字随便几行
</div>

运行结果如下:

我们看到只显示了三行,那是因为我-webkit-line-clamp: 3。这里设置为3.

因使用了WebKit的CSS扩展属性,该方法适用于WebKit浏览器及移动端;

-webkit-line-clamp用来限制在一个块元素显示的文本的行数。 为了实现该效果,它需要组合其他的WebKit属性。

如结合如下属性:

  • display: -webkit-box; 必须结合的属性 ,将对象作为弹性伸缩盒子模型显示 。
  • -webkit-box-orient 必须结合的属性 ,设置或检索伸缩盒对象的子元素的排列方式 。

 斜三角形并带文字效果

效果如下图所示:

HTML如下:

  <div class="font-topright"">待完工</div>
  <div class="triangle-topright mui-badge-orange"></div>
  <div class="font-seal">待料</div>

CSS代码(注意样式的命名,不要搞神马大小写,建议用-或者_连接,统一使用小写):

.font-seal {
    font-size: 12px;z-index: 2;position: absolute;right:14px;top: 35px;    border: 1px solid #F73A3C;
    transform: rotate(45deg);width: 53px;line-height: 20px;text-align: center;color: #F73A3C;font-weight: bold;
}

/**
 * 三角形气泡
 */
.triangle-topright {
    width: 0;height: 0;border-top: 44px solid #FD9D2D;border-left: 2rem solid transparent;
}
.font-topright {
    font-size: 12px;z-index: 2;position: absolute;right: -4px;top: -2px;
    transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);
    -ms-transform: rotate(45deg);-o-transform: rotate(45deg);width: 43px;line-height: 43px;text-align: center;color: #FFFFFF;
}
.mui-badge.mui-badge-orange{background-color:#FC9C2D;color:#FFFFFF;}

 时间轴效果

时间轴设计的难点在于所有的节点都是动态渲染的,最新的节点又和其它节点的样式不一致,节点的显示位置比较难控制,还有就是节点之间的连线必须恰到好处的把各个节点连接起来。

最终渲染的HTML代码:

<body class="mui-ios mui-ios-11 mui-ios-11-0">
    <div id="app" class="mui-content" style="background-color: rgb(255, 255, 255);">
        <div class="empty-container" style="display: none;">
            <div class="nodata-info">暂无相关内容</div>
            <div class="nodata-icon">
                <span class="mui-icon iconfont icon-wuneirong"></span>
            </div>
        </div>
        <section id="cd-timeline" class="cd-container" style="">
            <div class="cd-timeline-block">
                <div class="cd-timeline-img cd-picture"></div>
                <div class="cd-timeline-content">
                    <div>用户4,工单结束</div> <div class="cd-date">2018-05-22 14:33:58</div>
                </div>
            </div>
            <div class="cd-timeline-block">
                <div class="cd-timeline-img cd-movie"></div>
                <div class="cd-timeline-content">
                    <div>用户4,工作人员到场签到</div>
                    <div class="cd-date">2018-05-22 14:33:44</div>
                </div>
            </div><div class="cd-timeline-block">
                <div class="cd-timeline-img cd-movie"></div> <div class="cd-timeline-content">
                    <div>用户4,分配工作人员</div>
                    <div class="cd-date">2018-05-22 14:33:34</div>
                </div>
            </div>
            <div class="cd-timeline-block">
                <div class="cd-timeline-img cd-movie"></div>
                <div class="cd-timeline-content"><div>用户4,提交报修单</div> <div class="cd-date">2018-05-21 18:06:44</div></div>
            </div>
        </section>
    </div>
</body>

CSS样式timeline.css

[v-cloak] {display: none !important;}/*visibility: hidden;*/
/* -------------------------------- 
Primary style
-------------------------------- */
/*html{background-color: #FFFFFF;}*/
.mui-bar{background-color: #449DED;}
.mui-bar-nav .mui-icon {color: #FFFFFF;}
.mui-title {color: #fff;}
*, *:after, *:before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
img {max-width: 100%;}
/* -------------------------------- 
Modules - reusable parts of our design
-------------------------------- */
.cd-container {
  /* this class is used to give a max-width to the element it is applied to, and center it horizontally when it reaches that max-width */
  width: 100%;max-width: 1170px;margin: 0;
}
.cd-container::after {
  /* clearfix */
  content: '';display: table;clear: both;
}
/* -------------------------------- 
Main components 
-------------------------------- */
#cd-timeline {
  position: relative;padding: 0;margin-top: 0;margin-bottom: 1em;
}
/*#cd-timeline::before {
  content: '';position: absolute;top: 0;left: 18px;
  height: 80%;width: 1px;background: #C3E3FF;top:20px;
}*/
.cd-timeline-block:before{
      content: '';position: absolute;height: 67px;width: 1px;
    background: #C3E3FF;left: 25px;bottom: -28px;
}
.cd-timeline-block:first-child:before{
    top: 28px;
}
.cd-timeline-block:last-child:before{
    height: 0px;
}
#cd-timeline::after {
    height: 0px;
}
@media only screen and (min-width: 1170px) {
  #cd-timeline {
    margin-top: 3em;margin-bottom: 3em;
  }
#cd-timeline::before {
    left: 50%;margin-left: -2px;}
}
.cd-timeline-block {
  position: relative;margin: 2px 0 0 0;
}
.cd-timeline-block:after {
  content: "";display: table;clear: both;
}
.cd-timeline-block:first-child {
  margin-top: 0;
}
.cd-timeline-block:last-child {
  margin-bottom: 0;
}
@media only screen and (min-width: 1170px) {
  .cd-timeline-block {
    margin: 4em 0;
  }
  .cd-timeline-block:first-child {
    margin-top: 0;
  }
  .cd-timeline-block:last-child {
    margin-bottom: 0;
  }
}
.cd-timeline-img {
  position: absolute;top: 0;left: 0;width: 16px;height: 16px;border-radius: 50%;
  margin-top: 10px;box-shadow: 0 0 0 5px #DDEEFE;/*inset 0 2px 0 #60B2FB, 0 3px 0 5px #DDEEFE;*/
}
.cd-timeline-img img {
  display: block;width: 24px;height: 24px;
  position: relative;left: 50%;top: 50%;margin-left: -12px;margin-top: -12px;
}
.cd-timeline-img.cd-picture {
  background: #60B3FC; margin-left: 17px;margin-top: 25px;
}
.cd-timeline-img.cd-movie {
  background: #60B2FB; left: 21px;width: 10px;height: 10px;box-shadow:none;top:16px;
}
.cd-timeline-img.cd-location {
  background: #f0ca45;
}
@media only screen and (min-width: 1170px) {
  .cd-timeline-img {
    width: 60px;height: 60px;left: 50%;margin-left: -30px;
    /* Force Hardware Acceleration in WebKit */
    -webkit-transform: translateZ(0);-webkit-backface-visibility: hidden;
  }
  .cssanimations .cd-timeline-img.is-hidden {
    visibility: hidden;
  }
  .cssanimations .cd-timeline-img.bounce-in {
    visibility: visible;-webkit-animation: cd-bounce-1 0.6s;
    -moz-animation: cd-bounce-1 0.6s; animation: cd-bounce-1 0.6s;
  }
}
.cd-timeline-content {
  position: relative;margin-left: 50px;background: white;
  border-radius: 0;padding: 0.4em;box-shadow: 0 1px 0 #d7e4ed;
}
.cd-timeline-content:after {
  content: "";display: table;clear: both;
}
.cd-timeline-content h2 {
  color: #303e49;
}
.cd-timeline-content p, .cd-timeline-content .cd-read-more, .cd-timeline-content .cd-date {
  font-size: 13px;font-size: 0.8125rem;
}
.cd-timeline-content .cd-read-more, .cd-timeline-content .cd-date {
  display: inline-block;
}
.cd-timeline-content p {
  margin: 1em 0;line-height: 1.6;
}
.cd-timeline-content .cd-read-more {
  float: right;padding: .8em 1em;
  background: #acb7c0;color: white;border-radius: 0.25em;
}
.no-touch .cd-timeline-content .cd-read-more:hover {
  background-color: #bac4cb;  
}
a.cd-read-more:hover{text-decoration:none; background-color: #424242;  }
.cd-timeline-content .cd-date {
  float: left;padding: .4em 0;color: #A3A3A3;
}
.cd-timeline-content::before {
  content: '';position: absolute;top: 9px;right: 100%;height: 0;width: 0;
  border: 7px solid transparent;border-right: 7px solid white;
}
@media only screen and (min-width: 768px) {
  .cd-timeline-content h2 {
    font-size: 20px;font-size: 1.25rem;
  }
  .cd-timeline-content p {
    font-size: 16px;font-size: 1rem;
  }
  .cd-timeline-content .cd-read-more, .cd-timeline-content .cd-date {
    font-size: 14px;font-size: 0.875rem;
  }
}
@media only screen and (min-width: 1170px) {
  .cd-timeline-content {
    margin-left: 0;padding: 1.6em; width: 45%;
  }
  .cd-timeline-content::before {
    top: 24px;left: 100%;border-color: transparent;border-left-color: white;
  }
  .cd-timeline-content .cd-read-more {
    float: left;
  }
  .cd-timeline-content .cd-date {
    position: absolute;width: 100%;left: 122%;top: 6px;font-size: 16px;font-size: 1rem;
  }
  .cd-timeline-block:nth-child(even) .cd-timeline-content {
    float: right;
  }
  .cd-timeline-block:nth-child(even) .cd-timeline-content::before {
    top: 24px;left: auto;right: 100%;border-color: transparent;border-right-color: white;
  }
  .cd-timeline-block:nth-child(even) .cd-timeline-content .cd-read-more {
    float: right;
  }
  .cd-timeline-block:nth-child(even) .cd-timeline-content .cd-date {
    left: auto;right: 122%;text-align: right;
  }
  .cssanimations .cd-timeline-content.is-hidden {
    visibility: hidden;
  }
  .cssanimations .cd-timeline-content.bounce-in {
    visibility: visible;-webkit-animation: cd-bounce-2 0.6s;
    -moz-animation: cd-bounce-2 0.6s;animation: cd-bounce-2 0.6s;
  }
}
@media only screen and (min-width: 1170px) {
  /* inverse bounce effect on even content blocks */
  .cssanimations .cd-timeline-block:nth-child(even) .cd-timeline-content.bounce-in {
    -webkit-animation: cd-bounce-2-inverse 0.6s;
    -moz-animation: cd-bounce-2-inverse 0.6s; animation: cd-bounce-2-inverse 0.6s;
  }
}
.cd-timeline-content div{height: 21px;line-height: 21px;}
.cd-timeline-content div:first-child{
    color: #6DB6FE;font-size: 14px;line-height: 25px;
}
.cd-timeline-content div:last-child{line-height: 18px;}
/*为空*/
.empty-container{text-align:center;padding: 30% 0;background-color:#F5F5F5;overflow:hidden;height: 100%;position: fixed;width: 100%;}
.nodata-info{color:#C7C3C2;}
.nodata-icon{color:#C7C3C2;margin-top:25px;}
.nodata-icon .mui-icon{font-size:120px;}
View Code

我这里原来是使用了vue.js,理论上支持N个时间节点,原代码如下:

<div id="app" class="mui-content" style="background-color: #FFFFFF;">
            <div v-show="isEmptyData" class="empty-container" v-cloak>
                <div class="nodata-info">暂无相关内容</div>
                <div class="nodata-icon"><span class="mui-icon iconfont icon-wuneirong"></span></div>
            </div>
            <section v-show="list.length>0" id="cd-timeline" class="cd-container" v-cloak>
                <div v-for="(item,index) in list" class="cd-timeline-block">
                    <div class="cd-timeline-img" v-bind:class="[index==0?'cd-picture':'cd-movie']"></div>
                    <div class="cd-timeline-content">
                        <div v-text="item.text"></div>
                        <div class="cd-date" v-text="item.t"></div>
                    </div>
                </div>
            </section>
        </div>

js代码:

            var vm = new Vue({
                el: '#app',
                data: {
                    isEmptyData:false,
                    list: []
                },
                mounted: function () {
                    mui.init();
                    this.list = [{ "text": "用户4,工单结束", "t": "2018-05-22 14:33:58" }, { "text": "用户4,工作人员到场签到", "t": "2018-05-22 14:33:44" }, 
{ "text": "用户4,分配工作人员", "t": "2018-05-22 14:33:34" }, { "text": "用户4,提交报修单", "t": "2018-05-21 18:06:44" }];
}});

 MUI是非常轻量级的移动前端框架,而vue.js也是极简而优雅的mvvm框架,所以他们两合在一起使用实在是太方便了,不过他们两一起使用的同时会存在许多坑,若要避开这些坑,你需要知道MUI和vue.js他们的运行机制,其实也就是Dom操作、mui的生命周期同数据驱动、vue.js生命周期它们之间区别。

webstorm 2018 激活破解方法大全

posted @ 2018-05-22 15:07  邹琼俊  阅读(17274)  评论(5编辑  收藏  举报
-->