win8效果的横向布局

有一个月没写过博客了,自己的博客也没有看过,前段时间一直在忙着写代码,公司有一个制漆的产品,与传统纵向布局不一样,要求页面横向布局,类似win8的那种布局效果,最开始,我也没有什么头绪,然后硬着头皮做了,后来,遇到了很多麻烦,我网上查了一些资料,但都不太好,只好自己做了,在做的过程中,突然想到,flex布局,我就试了一下,成功了

<!doctype html>
<head>
    <style type="text/css">
	*{
		box-sizing:border-box;
		padding:0;margin:0;border:0
	}
	html,body{
		height:100%; 
		display: box;              /* OLD - Android 4.4- */
		display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
		display: -ms-flexbox;      /* TWEENER - IE 10 */
		display: -webkit-flex;     /* NEW - Chrome */
		display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
		display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
	}
	.leftside,.rightside{
		height:100%;
		min-width:200px;
		margin-right:10px;
	}
	.rightside{
		margin-right:0px;
	}
	.leftcardswrap,.rightcardswrap{
		/*Firefox*/
		height:-moz-calc(100%);
		/*chrome safari*/
		height:-webkit-calc(100%);
		/*Standard */
		height:calc(100%);
		width:100%;
		background:#ccc;
		overflow-x:hidden;
		overflow-y:auto;
		padding:5px;
		}
	.scroll{
		height:100%;
	}
    .scroll-top,.scroll-bottom{
		display: box;              /* OLD - Android 4.4- */
		display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
		display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
		display: -ms-flexbox;      /* TWEENER - IE 10 */
		display: -webkit-flex;     /* NEW - Chrome */
		display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
		height:50%;
		padding-bottom:5px;
    }
    .cards-wrap{
        -webkit-box-flex: none;      /* OLD - iOS 6-, Safari 3.1-6 */
		-moz-box-flex: none;         /* OLD - Firefox 19- */
		-webkit-flex: none;          /* Chrome */
		-ms-flex: none;              /* IE 10 */
		flex: none;   
        position:relative;
        float:left;
		/*Firefox*/
		height:-moz-calc(100%);
		/*chrome safari*/
		height:-webkit-calc(100%);
		/*Standard */
		height:calc(100%);
        min-width:200px;
        background:#ccc;
        margin-right:10px;
		display: inline-block;
		*display: inline;
		*zoom: 1;
		padding:5px;
		overflow-x:hidden;
		overflow-y:auto;
    }
	.card{
		min-height:200px;
		width:100%;
		background:green;
		margin-bottom:5px;
	}
    </style>
</head>
<body>
<div class="leftside">
	<div class="leftcardswrap">
		<div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div>
	</div>
</div>
<div class="scroll">
	<div class="scroll-top">
		<div class="cards-wrap"><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div></div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
	</div>
	<div class="scroll-bottom">
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
		<div class="cards-wrap">111111</div>
	</div>
</div>
<div class="rightside">
	<div class="rightcardswrap">
		<div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div>
	</div>
</div>
</body>
</html>

上面是我的代码

运行出来的效果如下:

flex布局轻松搞定了

<!doctype html>
<head>
    <style type="text/css">
    *{box-sizing:border-box;}
    html{
    height:100%; 
    display: box;              /* OLD - Android 4.4- */
    display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
    display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
    display: -ms-flexbox;      /* TWEENER - IE 10 */
    display: -webkit-flex;     /* NEW - Chrome */
    display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
  }
    body{
    display:flex;
    display: box;              /* OLD - Android 4.4- */
    display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
    display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
    display: -ms-flexbox;      /* TWEENER - IE 10 */
    display: -webkit-flex;     /* NEW - Chrome */
    display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
    }
    .leftside,.rightside{height:100%;width:200px;margin-right:10px;}
    .rightside{margin-right:0px;}
    .leftcardswrap,.rightcardswrap{height:calc(100%);width:100%;background:#ccc;overflow-x:hidden;overflow-y:auto;padding:5px;}
    .scroll{height:100%;}
    .scroll-top,.scroll-bottom{
        display: box;              /* OLD - Android 4.4- */
        display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
        display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
        display: -ms-flexbox;      /* TWEENER - IE 10 */
        display: -webkit-flex;     /* NEW - Chrome */
        display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
        height:50%;
        padding-bottom:5px;
    }
    .cards-wrap{
        -webkit-box-flex: none;      /* OLD - iOS 6-, Safari 3.1-6 */
        -moz-box-flex: none;         /* OLD - Firefox 19- */
        -webkit-flex: none;          /* Chrome */
        -ms-flex: none;              /* IE 10 */
        flex: none;   
        position:relative;
        float:left;
        height:calc(100%);
        width:200px;
        background:#ccc;
        margin-right:10px;
        display: inline-block;
        *display: inline;
        *zoom: 1;
        padding:5px;
        overflow-x:hidden;
        overflow-y:auto;
    }
    .card{
    min-height:200px;
    width:100%;
    background:green;
    margin-bottom:5px;
    }
    </style>
</head>
<body>
<div class="leftside">
    <div class="leftcardswrap">
        <div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div>
    </div>
</div>
<div class="scroll">
    <div class="scroll-top">
        <div class="cards-wrap"><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div></div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
    </div>
    <div class="scroll-bottom">
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
        <div class="cards-wrap">111111</div>
    </div>
</div>
<div class="rightside">
    <div class="rightcardswrap">
        <div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div><div class="card"></div>
    </div>
</div>
</body>
</html>

win8横向布局:

注意点:

1、flex的兼容性写法

2、inline-block的兼容性写法

3、html标签设置高度为100%时,body高度不能设置为100%,否则会出现滚动条

4、html与body高度相差10个像素的原因是因为设置了!doctype html,解决办法是html,body{margin:0px;padding:0px;}这样的话问题三就不会出现了。

5、如果body与html不设置100%的话,body里面会出现滚动条。

6、html,body{margin:0px;padding:0px;height:100%;display:flex}这个是解决横向布局的终极解决方法。

7、box-sizing要全局设置好,否则会出现各种计算问题。

8、原理上,flex里面的排列方式是一行显示,但如果要显示两行的话,给这两行加上父元素,display:block;就可以。

时隔一年,我再来做这个,越来越简单了,废话不多说,直接上代码

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <style type="text/css">
    html,body{
      height:100%;
      padding:0px;
      overflow:hidden;
      width:100%;
    }
    .content{
      width:100%;
      height:100%;
      overflow-x:auto;
      overflow-y:hidden;
      padding:0px;
      background:#ccc;
      float:left;
      white-space:nowrap;
    }
    .item{
      display:inline-block;
      width:80px;
      height:100%;
      margin-right:4px;
    }
    .itemTop,.itemBottom{
      height:50%;
      width:100%;
      box-sizing:border-box;
    }
    .itemTop{
      background:green;
      border-bottom:10px solid #ccc;
    }
    .itemBottom{
      background:red;
    }
  </style>
</head>
<body>
<div class="content">
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div>  
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
  <div class="item">
    <div class="itemTop"></div>
    <div class="itemBottom"></div>
  </div> 
</div>
</body>
</html>

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏编程微刊

echarts统计图踩坑合集

将图标主标题颜色修改成红色,只需要在 title:里面添加 textStyle: {color: 'red' }即可

482
来自专栏Java技术分享圈

杨老师课堂之JavaScript悬浮事件(鼠标移入移出事件)

    onmouseover 代表的是鼠标指针移动到指定的对象上时发生某个动作;

853
来自专栏程序员叨叨叨

手把手教你打造RecyclerView滚动特效

最近开发中遇到这样的需求,recyclerview的item随滚动改变大小和透明度。这个效果看起来挺有动感的,似乎实现起来有点复杂,其实不然,接下来将带领大家手...

741
来自专栏james大数据架构

jQuery操作Select

jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code....

1867
来自专栏阮一峰的网络日志

CSS3圆角详解

CSS3是样式表(style sheet)语言的最新版本,它的一大优点就是支持圆角。

752
来自专栏Android先生

RecyclerView 自定义ItemDecoration从入门到实现吸顶效果

RecyclerView性能和自由度相比ListView强大很多,但很恼人的是它没有像ListView一样默认提供分割线。

751
来自专栏Python爱好者

Python绘制分形树(一)

1448
来自专栏zcqshine's blog

ajaxFileUpload+ThinkPHP+jqGrid 图片上传与显示

3184
来自专栏编程心路

Bootstrap学习文档(二)

Bootstrap 中把一些标签的样式重置了,也即是为一些标签设置了带有 Bootstrap 风格的样式,如 h 标签,p 标签等等,这其中包含了 HTML5 ...

1285
来自专栏web开发

自实现PC端jQuery版轮播图

  最近其他项目不是很忙,被安排给公司的官网项目做一个新的页面(之前没接触公司官网项目),其中有一个用到轮播图的地方,最开始想直接用swiper.js插件实现就...

3377

扫码关注云+社区