Code Monkey

于工开始移山

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Vertical Align Center</title>
  <style>
    .box {
      /* needed to set the height of child elements */
      position:absolute; 
      top:20px; 
      left:30px;
      height: 500px;
      width: 300px;
      background-color: red;
      overflow: hidden;
    }
    
    .wrapper {
      /* set the height of the element which contains what you want to center */
      height: 100%;
      /* these styles are optional, to set width horizontally center the page */
      width: 100%;
      margin: 0;
    }
    
    .wrapper:before, .container {
      /* these are the important styles for the centered element: */
      display: inline-block;
      vertical-align: middle;
    }
    
    .wrapper:before {
      /* this is the important part */
      content: '';
      width: 0;
      height: 100%;
      /* this just takes care of whitespace added by having display:inline-block (there are other methods) */
      margin-left: -0.25em;
    }
    
    .container {
      /* extra styling */
      background: #ddd;
      border-radius: 5px;
      color: #222;
      font-family: 'Helvetica Neue', Helvetica, sans-serif;
      width: 100%;
      white-space: normal; 
      cursor: text; 
      word-wrap: break-word; 
      outline: none;
    }
  </style>
</head>
<body>

<div class="box">
  <div class="wrapper">
    <div class="container" contenteditable="true" spellcheck="false">
    &nbsp;
    </div>
  </div>
</div>

</body>
</html>

 

posted on 2014-11-28 09:53  MSchina  阅读(159)  评论(0)    收藏  举报