专栏首页杨龙飞前端win8效果的横向布局

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 条评论
登录 后参与评论

相关文章

  • 网页html结构搭建方法总结

    windseek
  • 大屏数据展示之数字滑动动态显示

    接到一个大屏数据的需求,要是实时展示用户数,并且动画效果是翻转显示,折腾了半个多小时,写了一个demo出来,上代码

    windseek
  • BFC概念和作用,触发条件

    windseek
  • 零基础html5+div+css+js网页开发教程第006期 网页快速开发技巧

    上一节,我们学习了hbuilder的快速开发工具的简单实用,本机额,我们来介绍这个工具相关的快速开发技巧。

    刘金玉编程
  • HTML&CSS书写规范

    第一部分:HTML书写规范: 1.1 HTML整体结构: 1.1.1:HTML基础设施: 文档以"<!DOCTYPE...>"首行顶格开始,推荐使用"<!DOC...

    用户1149564
  • HTML规范 - 整体结构

    申霖
  • jquery 选中某一行

    Dream城堡
  • 前端-part8-jQurey操作样式一

    少年包青菜
  • vue弹出层 +内容手风琴 简单实现

    yangdongnan
  • 一起学爬虫——使用xpath库爬取猫眼电

    之前分享了一篇使用requests库爬取豆瓣电影250的文章,今天继续分享使用xpath爬取猫眼电影热播口碑榜

    py3study

扫码关注云+社区

领取腾讯云代金券