CSS 盒子水平排布的三种方式


<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>盒子水平排布的三种方式title>
	<style>
		.contain {
			width: 900px;
			height: 600px;
			margin: 100px auto;
		}
		.block {
			width: 100%;
			height: 33.33%;
			font-size: 50px;
			line-height: 200px;
			text-align: center;
			border: 1px solid #ddd
		}

		/* 方法一 flex 方法 */
		.block:first-child{
			display: flex;
		}
		.inA:nth-child(1){
			height: 100%;
			flex: 1
		}
		.inA:nth-child(2){
			height: 100%;
			flex: 1
		}
		.inA:nth-child(3){
			height: 100%;
			flex: 1
		}
		.block:nth-child(2){
			position: relative;
		}

		/* 方法二 绝对定位方法 */
		.inB{
			position: absolute;
			height: 100%;
			width: 33.333%
		}
		.inB:nth-child(1) {
			left: 0;
		}
		.inB:nth-child(2) {
			left: 33.33%;
		}
		.inB:nth-child(3) {
			right: 0;
		}

		/* 方法三 浮动方法 */
		.inC{
			float: left;
			width: 33.33%;
		}

		/* 颜色 */
		.bacRed {
			background: red;
		}
		.bacsky {
			background: skyblue;
		}
		.bacyellow {
			background: yellow
		}
	style>
head>
<body>
	<div class="contain">
		<div class="block">
			<div class="inA bacRed">div>
			<div class="inA bacsky">div>
			<div class="inA bacyellow">div>
		div>
		<div class="block">
			<div class="inB bacsky">div>
			<div class="inB bacyellow">div>
			<div class="inB bacRed">div>
		div>
		<div class="block">
			<div class="inC bacyellow">div>
			<div class="inC bacRed">div>
			<div class="inC bacsky">div>
		div>
	div>
body>
html>

CSS 盒子水平排布的三种方式_第1张图片

你可能感兴趣的:(CSS/CSS3,css)