大家好,又见面了,我是你们的朋友全栈君。
使用flex布局实现居中布局的步骤:
align-items: center;
代码示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style> .a {
display: flex; /* 垂直居中 */ align-items: center; background-color: royalblue; height: 100px; } .a .one {
background-color: aqua; height: 20px; } .a .two {
margin-left: auto; background-color: red; height: 20px; } </style>
</head>
<body>
<div class="a">
<div class="one">111111111111111111</div>
<div class="two">222222222222222222</div>
</div>
</body>
</html>
效果:
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/132357.html原文链接:https://javaforall.cn