CSS page layout basis - the Holy Grail layout and Flying wing

Line Layout

Multi-column layout

Holy Grail layout

Flying wing

 

First, the line layout

 

 

 

Vertical horizontal center line layout

Note: There is no use margin: 0 auto; let it centered horizontally, but the use of absolutely positioned layout, then set the top: 50%; left: 50 %; however this is not enough light settings, because it is not vertically centered horizontally , because it does not consider their own width and height, so here provided margin-left margin-top, and again according to this aspect on a foundation box itself. If only the top: 50%; left: 50 %; provided without margin-left and margin-top, the effect is as follows:

 

code show as below:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Document</title>
	<style type="text/css">
		* {
			margin: 0;
			padding: 0;
			background: burlywood;
		}
		.container {
			background: rgb(136, 89, 182);
			height: 200px;
			width: 800px;
			text-align: center;
			margin: 0 auto;
			position: absolute;
			top: 50%;
			left: 50%;
		}
	</style>
</head>
<body>
	<div class = "container"> This is the content of the page </ div> 
	
</ body> 
</ HTML>

  

The final results show the following:

 

 

 

Second, multi-column layout

 

Third, the Holy Grail layout (see specific ideas pdf document)

 

 

 

 

Code:

<!DOCTYPE html>
<html>

<head>
    <title>圣杯布局</title>
    <meta charset="utf-8">
    <style type="text/css">
    * {
        margin: 0;
        padding: 0;
    }

    body {
        min-width: 700px;
    }

    .header,
    .footer {
        float: left;
        width: 100%;
        background: #ddd;
        height: 40px;
        line-height: 40px;
        text-align: center;
    }

    .container {
        padding: 0 220px 0 200px;
    }

    .left,
    .middle,
    .right {
        position: relative;
        float: left;
        min-height: 300px;
    }

    .left {
        margin-left: -100%;
        left: -200px;
        width: 200px;
        background: #f00;
    }

    .right {
		width: 220px;
		margin-left: -220px;
        right: -220px;
        background: #30a457;
    }

    .middle {
        width: 100%;
        background: #1a5acd;
    }
    </style>
</head>

<body>
    <div class="header">
        <h4>header</h4>
    </div>
    <div class="container">
        <div class="middle">
            <h4>middle</h4>
            <p>
                这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容
            </p>
        </div>
        <div class="left">
            <h4>left</h4>
            <p>
                这是页面的左边 这是页面的左边 这是页面的左边 这是页面的左边 这是页面的左边 这是页面的左边
            </p>
        </div>
        <div class="right">
            <h4>right</h4>
            <p>
                这是页面的右边 这是页面的右边 这是页面的右边 这是页面的右边
            </p>
        </div>
    </div>
    <div class="footer">
        <h4>footer</h4>
    </div>
</body>

</html>

  

 

 

 

四、双飞翼布局(圣杯布局改良版,pdf)(相比较圣杯布局,去掉左边,右边和中间的最外层包裹,所以不用相对定位做)

 

 

代码:

<!DOCTYPE html>
<html>

<head>
    <title>圣杯布局</title>
    <meta charset="utf-8">
    <style type="text/css">
    * {
        margin: 0;
        padding: 0;
    }

    body {
        min-width: 700px;
    }

	.header,
	.footer {
		border: 1px solid #333;
        background: #ddd;
        height: 40px;
        line-height: 40px;
        text-align: center;
    }
    .sub,
    .middle,
    .extra {
        float: left;
		min-height: 300px;
	}
	.extra {
		margin-left: -220px;
        width: 220px;
        background: #30a457;
	}
    .sub {
        margin-left: -100%;
        width: 200px;
        background: #f00;
    }
    .main-inner {
		margin-left: 200px;
		margin-right: 220px;
		min-height: 300px;
        background: #1a5acd;
	}
	.footer {
		clear: both;
	}
    </style>
</head>

<body>
    <div class="header">
        <h4>header</h4>
    </div>
	<div class="middle">
		<div class="main-inner">
			<h4>middle</h4>
			<p>
				这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容 这是页面的主体内容
			</p>
		</div>
	</div>
	<div class="sub">
		<h4>left</h4>
		<p>
			这是页面的左边 这是页面的左边 这是页面的左边 这是页面的左边 这是页面的左边 这是页面的左边
		</p>
	</div>
	<div class="extra">
		<h4>right</h4>
		<p>
			这是页面的右边 这是页面的右边 这是页面的右边 这是页面的右边
		</p>
	</div>
    <div class="footer">
        <h4>footer</h4>
    </div>
</body>

</html>

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/helloCindy/p/11616980.html