博主信息
博文 35
粉丝 0
评论 0
访问量 51780
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
自己编写简单的框架,并用来制作一个UI页面-2019年9月11日
Victor的博客
原创
1340人浏览过

编写一个简单的框架,应用到一个实际的页面中

本次课程中学习了前端的封装方式,也从phpcn UI中学习了重置和预制属性的基本内容;

封装的原理很简单,可是想自己搞出一个合理有效的封装框架,实在太不容易了,形成不了系统。

所以本次作业中,我尝试的方法是实现代码的复用,首先实现的是水平垂直居中、绝对定位和flexbox的基本设置。


在仿写用户手册中仅用到绝对定位和单行内联元素垂直居中:

yonghushouce.jpg

代码部分

实例
// 绝对定位:使该元素相对于父容器(relative)或者body实现绝对定位
@mixin ele-fixed-lt($left: 0, $top: 0, $ele-width: auto, $ele-height: auto) {
    position: absolute;
    width: $ele-width;
    height: $ele-height;
    left: $left;
    top: $top;
    // z-index: 999;
}

@mixin ele-fixed-rb($right: 0, $bottom: 0, $ele-width: auto, $ele-height: auto) {
    position: absolute;
    width: $ele-width;
    height: $ele-height;
    right: $right;
    bottom: $bottom$bottom;
}

@mixin ele-flexbox($box-width: auto, $box-height: auto, $direction: row, $wrap: nowrap) {
    display: flex;
    width: $box-width;
    height: $box-height;
    flex-direction: $direction;
    flex-wrap: $wrap;
}

// 绝对居中:使一个元素相对于父容器或者body实现水平垂直居中
// xy-center-box:不用此类名,则元素针对body绝对居中;
// xy-center-box和xy-center-ele所指元素都需要有具体宽度和高度;
@mixin xy-center-ele($ele-width: 100px, $ele-height: 100px) {
    position: absolute;
    width: $ele-width;
    height: $ele-height;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    // z-index: 999;
}

@mixin xy-center-box($box-width: auto, $box-height: 300px) {
    position: relative;
    width: $box-width;
    height: $box-height;
}

// 以下是练习内容
// .xy-center-box {
//     @include xy-center-box();
//     border: 1px solid #000;
//     background-color: lightcyan;
//     .xy-center-ele {
//         @include xy-center-ele();
//         background-color: lightcoral;
//     }
// }
//============================================================
// 绝对居中:父容器利用flex来实现其内部子元素水平垂直居中
@mixin xy-center-flexbox($box-width: auto, $box-height: auto) {
    display: flex;
    width: $box-width;
    height: $box-height;
    justify-content: center;
    align-items: center;
}

// .xy-center-flexbox {
//     @include xy-center-flexbox();
//     border: 1px solid #000;
//     background-color: lightcyan;
//     .xy-center-ele {
//         width: 100px;
//         height: 100px;
//         background-color: lightcoral;
//     }
// }
//===============================================
// 绝对居中:使用table来实现水平垂直居中
// xy-center-table:父元素;
// xy-center-table-ele;子元素
@mixin xy-center-table-ele() {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}

@mixin xy-center-table($box-width: auto, $box-height: auto) {
    display: table;
    width: $box-width;
    height: $box-height;
}

// .xy-center-table {
//     @include xy-center-table();
//     border: 1px solid #222;
//     .xy-center-table-ele {
//         @include xy-center-table-ele();
//         padding-right: 20px;
//     }
// }
//===========================================================
// 水平居中:多元素实现水平居中
@mixin x-center-eles($ele-width:auto, $ele-height:auto) {
    display: inline-block;
    // display: inline;
    /*hack IE*/
    // zoom: 1;
    /*hack IE*/
    margin: 0;
    padding: 0;
    width: $ele-width;
    line-height: $ele-height;
}

@mixin x-center-box($box-width: auto, $box-height: auto) {
    text-align: center;
    width: $box-width;
    height: $box-height;
}

.x-center-box {
    @include x-center-box();
    border: 1px solid #222;
    .x-center-eles {
        @include x-center-eles(100px, 60px);
        &:hover {
            color: red;
            border-bottom: 2px solid red;
        }
    }
}

运行实例 »
点击 "运行实例" 按钮查看在线实例






批改状态:合格

老师批语:看上去还不错, 重点在于理解思想
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学