Meg*_*att 3 html css vertical-alignment flexbox css-transforms
如何使用flexbox布局垂直居中旋转文本?我想要看起来像这样的东西:
这是我到目前为止的内容:
html, body { height: 100%; }
body { background-color: #efefef; }
body > div {
align-content: center;
background-color: white;
border: 1px solid black;
display: flex;
height: 100%;
width: 25px;
}
body > div > div {
flex: 1;
transform: rotate(-90deg);
}Run Code Online (Sandbox Code Playgroud)
<div>
<div>
Where did I go?
</div>
</div>Run Code Online (Sandbox Code Playgroud)
使用以下命令添加white-space: nowrap和水平居中并垂直居中:
align-items: center;
justify-content: center;
Run Code Online (Sandbox Code Playgroud)
(并且您不需要flex: 1!)
还删除了浏览器边距,并添加了box-sizing: border-box添加点睛之笔。
请参见下面的演示:
align-items: center;
justify-content: center;
Run Code Online (Sandbox Code Playgroud)
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
margin: 0;
}
body {
background-color: #efefef;
}
body > div {
background-color: white;
border: 1px solid black;
display: flex;
height: 100%;
width: 25px;
align-items: center;
white-space: nowrap;
justify-content: center;
}
body > div > div {
transform: rotate(-90deg);
}Run Code Online (Sandbox Code Playgroud)