简单CSS 布局

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

fill-right.png

<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

fill-left.png

<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

fill-bottom.png

<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

fill-top.png

<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

complex-layout.png

<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

hor-center.png

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

.center-vertical

ver-center.png

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

ver-hor center

ver-hor-center.png

<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
139239-20170920110920478-1738248932.jpg

关注我 

最后大家可以关注我和 css_layout项目 ^_^
Follow @wz2cool Star Fork

转载于:https://www.cnblogs.com/wz2cool/p/7560724.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值