首页 > 代码库 > 【writing-mode与absolute,auto】垂直居中

【writing-mode与absolute,auto】垂直居中

实现垂直方向margin:auto居中 
writing-mode:vertical-lr;改变垂直方向
技术分享
 技术分享
<!DOCTYPE html><html>      <head>            <meta charset="utf-8" />            <title></title>            <style type="text/css">            #father{                  width: 100%;                  height: 500px;                  background: lightcoral;                  writing-mode:vertical-lr;            }                  #son{                        background: lightblue;                        height: 200px;                        margin:auto;                        width: 200px;                        }            </style>      </head>      <body><div id="father">      <div id="son">       </div></div>      </body></html>

 

 
使用absolute,auto居中定位
设置其父类元素为relative属性,子元素为absolute属性
 技术分享

 

技术分享
<!DOCTYPE html><html>      <head>            <meta charset="utf-8" />            <title></title>            <style type="text/css">            #father{                   height: 500px;                  background: lightcoral;                position: relative;            }                  #son{                        background: lightblue;                        position: absolute;                        top: 0;                        bottom: 0;                        left: 0;                        right: 0;                        width: 200px;                        height: 100px;                        margin: auto;                        }            </style>      </head>      <body><div id="father">      <div id="son">       </div></div>      </body></html>

 

【writing-mode与absolute,auto】垂直居中