CSS Layout

CSS Layout 是对上下左右布局的一个简单封装,主要针对自己项目里面方便使用。

坚持组合大于继承的原则,复杂的布局也是由简单布局组成的,当你用习惯了,完全在布局上面不用再去写CSS 啦~

所以不习惯margin/padding-top/right/bottom/left-*的同学可以忽略。

大家可以使用免费cdn 做测试: https://gitcdn.xyz/repo/wz2cool/css_layout/0.1/dist/layout.min.css

(PS: 非前端专攻人士,至于你们觉得好不好,反正我是用的挺爽的_

项目地址:https://github.com/wz2cool/css_layout

.fill

填充父节点全部空间。

.fill-height

填充父节点高度空间。

.fill-width

填充父节点宽度空间。

.float-right

向右浮动。

.float-left

向左浮动。

.margin-/top/right/bottom/left-xx

margin 的上下左右

.padding-/top/right/bottom/left-xx

padding 的上下左右

.horizontal-container

.fill-right

<div class="horizontal-container fill-right" style="height: 100px;">
<div class="left-panel fill-height" style="background: #EE91AD; width: 150px;">
left panel (auto)
</div>
<div class="right-panel fill-height" style="background: #7171D1;">
right panel (fill rest)
</div>
</div>

在线demo

.fill-left

<div class="horizontal-container fill-left" style="height: 100px;">
<div class="right-panel fill-height" style="background: #7171D1; width: 150px;">
right panel (auto)
</div>
<div class="left-panel fill-height" style="background: #EE91AD;">
left panel (fill rest)
</div>
</div>

在线demo

.vertical-container

.fill-bottom

<div class="vertical-container fill-bottom" style="height: 400px;">
<div class="top-panel" style="background: #EE91AD; height: 100px;">
top panel (auto)
</div>
<div class="bottom-panel" style="background: #7171D1;">
bottom panel (fill rest)
</div>
</div>

在线demo

.fill-top

<div class="vertical-container fill-top" style="height: 400px;">
<div class="top-panel" style="background: #EE91AD; ">
top panel (fill rest)
</div>
<div class="bottom-panel" style="background: #7171D1;height: 100px;">
bottom panel (auto)
</div>
</div>

在线demo

complex hor-ver layout

<div class="vertical-container fill-bottom" style="height:300px;">
<div class="top-panel">
top (auto)
</div>
<div class="bottom-panel">
<!-- need fill height width -->
<div class="vertical-container fill-top fill">
<div class="top-panel">
<div class="left-panel fill-height">
left (auto)
</div>
<div class="right-panel fill-height">
<div class="horizontal-container fill-left fill">
<div class="right-panel fill-height">
right(auto)
</div>
<div class="left-panel fill-height">
center
</div>
</div>
</div>
</div>
</div>
<div class="bottom-panel">
bottom panel (auto)
</div>
</div>
</div>

.center-container

.center-horizontal

<div class="center-container center-horizontal" style="background: #EE91AD; width: 200px; height: 50px">
<div class="center-panel">
center item
</div>
</div>

.center-vertical

<div class="center-container center-vertical" style="background: #EE91AD; width: 200px; height: 50px">
<div class="center-panel">
center item
</div>
</div>

ver-hor center

<div class="center-container center-vertical" style="background: #EE91AD; width: 200px; height: 50px">
<div class="center-panel">
<div class="center-container center-horizontal">
<div class="center-panel">
<span>*</span> center item
</div>
</div>
</div>
</div>

仿照葡萄城举例

正好看到别人举例的一个布局: http://www.cnblogs.com/powertoolsteam/p/combine-flexbox-and-css-grids-for-layouts.html

我们立刻用我们的方法实现了一下: 在线demo

关注我 ##

最后大家可以关注我和 css_layout项目 _

Follow @wz2cool Star Fork

简单CSS 布局的更多相关文章

  1. 简单CSS布局留用

    1.导航栏固定显示代码,文字居中,z-index header{ position: fixed; top: 0px; left: 10%; width: 80%; height: 80px; bor ...

  2. (转)div+css 布局经验 - 最简单的 = 最不变形的(原创技巧)

    站酷几年了 一直饱受其恩泽 尤为感激 一直想奉献些什么 但是苦于水平 苦于奔波 今天静下心来 为大家奉献下 自己的div+css 经验 ,以下观点只代表 深海个人立场 希望为初学者提供一条" ...

  3. div+css 布局经验 - 最简单的 = 最不变形的(原创技巧)

    站酷几年了 一直饱受其恩泽 尤为感激 一直想奉献些什么 但是苦于水平 苦于奔波 今天静下心来 为大家奉献下 自己的div+css 经验 ,以下观点只代表 深海个人立场 希望为初学者提供一条" ...

  4. [CSS布局]简单的CSS三列布局

    前言 公司终于可以上外网了,近期在搞RN的东西,暂时脑子有点晕,等过段时间再来写点总结.倒是最近有个新学前端的同学经常会问一些基础知识,工作空闲写了小Demo给他看,全是很基础的知识,纯粹是顺便记录在 ...

  5. 界面设计技法之css布局

    css布局之于页面就如同ECMAScript之于JS一般,细想一番,html就如同语文,css就如同数学,js呢,就是物理,有些扯远,这里就先不展开了. 回到主题,从最开始的css到如今的sass(l ...

  6. CSS布局 - 三栏布局

    CSS布局技术可谓是前端技术中最基础的技术,就是因为基础,所以我认为要更加熟练,深入的去掌握,去梳理. 一. 传统 ---> 浮动实现的三栏布局 采用浮动实现的三栏布局有以下特点及注意事项: · ...

  7. CSS 布局

    近日开发中,总感觉页面布局方面力不从心.以前也曾学过这方面的内容,但是不够系统,因此我打算整理一下. 在web 页面中一般有 table 和 css+div 两种布局方式. 其中css+div 又分为 ...

  8. CSS布局经典—圣杯布局与双飞翼布局

    在我之前的博客网页整体布局完全剖析-剖完你不进来看一下么?中总结单列.两列.三列固宽与变宽布局,我还以为已经囊括了所有经典的网页布局方法了呢,当然除了CSS3的弹性盒模型没有涉及到,现在看来确实是自己 ...

  9. CSS篇之DIV+CSS布局

    <div></div> div与其他标签一样,也是一个XHTML所支持的标签. div是XHTML中指定的,远门用于布局设计的容器标记. 简单的CSS布局 头部 内容 页脚 & ...

随机推荐

  1. Jenkins 环境搭建

    本文为jenkins入手教程,全文分为 jenkins安装.系统管理(配置全局安全.全局工具配置.管理插件).创建项目(同时创建证书),管理视图,jenkins 客户端,执行构建.查看任务历史 一.j ...

  2. OminiMarkupPreview快捷键

    The default key bindings: Windows, Linux: Ctrl+Alt+O: Preview Markup in Browser. Ctrl+Alt+X: Export ...

  3. 深入理解JVM(七)——性能监控工具

    前言 工欲善其事必先利其器,性能优化和故障排查在我们大都数人眼里是件比较棘手的事情,一是需要具备一定的原理知识作为基础,二是需要掌握排查问题和解决问题的流程.方法.本文就将介绍利用性能监控工具,帮助开 ...

  4. 基于.netstandard的权限控制组件

    基于.netstandard的权限控制组件 Intro 由于项目需要,需要在 基于 Asp.net mvc 的 Web 项目框架中做权限的控制,于是才有了这个权限控制组件. 项目基于 .NETStan ...

  5. SVG图案

    前面的话 给SVG元素应用填充和描边,除了使用纯色和渐变外,还可以使用图案.本文将详细介绍SVG图案 概述 <pattern>可以实现重复的效果,在canvas中被翻译为模式,而在SVG中 ...

  6. 自动化测试:behave

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  7. Web桌面应用框架2:著名的WEB桌面应用分析

    前一篇文章里,分析了包括NW.js和electron这种纯JS框架在内的几种Web桌面应用开发方式,实际上还有一种最古老的方式,那就是嵌入WebView的方式. 嵌入WebView的方式和整个程序都是 ...

  8. js 中采用词法作用域

    所谓的 词法( 代码 )作用域, 就是代码在编写过程中体现出来的作用范围. 代码一旦写好, 不用执行, 作用范围就已经确定好了. 这个就是所谓词法作用域. 在 js 中词法作用域规则: 1.函数允许访 ...

  9. 父子一对多iframe,子iframe改子iframe元素

    $("iframe", parent.document).contents().find("#ProductNameIn").val(66666666); 1. ...

  10. Membership ——入门基础

    Membership是ASP.NET为我们提供的一套验证和存储用户凭证的框架.它可以帮助我们快速的开发用户登录.管理以及权限验证相关的模块,很多人可能会说Membership开发起来确实很快,但是总是 ...