---
title: "css div水平垂直居中"
author: "floydd"
date: "2007-09-02T16:14:00Z"
tags: []
slug: "css-div"
draft: false
lastmod: "2011-12-26T12:03:29Z"
id: 1326396
url: "https://floydd.iteye.com/blog/1326396"
---

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)&lt;STYLETYPE="text/css"&gt;...  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif).middle-demo-4{...}{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)height:400;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)width:100%;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)position:relative;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)background:#aaa;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif).middle-demo-4div{...}{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)position:absolute;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)top:50%;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)left:50%;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)background:blue  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif).middle-demo-4divdiv{...}{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)position:relative;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)top:-50%;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)left:-50%;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)background:yellow;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)overflow:hidden;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/STYLE&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;divclass=middle-demo-4&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;div&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;div&gt;helpipsumdolorsitamet,consectetueradipiscingelit.asdsadfs.&lt;br&gt;&lt;imgsrc=1.jpgwidth=140height=100&gt;asdsadfs.&lt;br&gt;asdsadfs.asdsadfs.&lt;br&gt;asdsadfs.asdsadfs.&lt;/div&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/div&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)&lt;/div&gt;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)