水平垂直居中

文字和元素 水平垂直居中

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<div class="box">
  <div class="boxContent">1sasdasdasdterterterteterteteterta</span>
</div>
</body>
</html>
    .box{
      position:relative;
      width:500px;
      height:500px;
      background-color:green;
    }
    .boxContent{
      position: absolute;
/*    width:200px;
      height:200px; */
      background-color:red;
      top:50%;
      left:50%;
      /* margin-top:-100px; */
      transform:translate(-50%, -50%);
      /* margin-left:-100px; */  
      word-break: break-all;
      word-wrap: break-word;
    }

clipboard.png

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章