-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css] 第93天 写出div在不固定高度的情况下水平垂直居中的方法? #907
Comments
我知道的有两种方法
|
父盒子相对定位 父盒子相对定位,子盒子绝对定位和margin |
自从用了弹性布局,我的居中对齐只有弹性布局。 |
不知道以后flex布局普及后,老的布局方式还有多大的用武之地 |
大家都很棒 我这里有一种新的方法
|
|
<template>
<div class="father">
<div class="son">
11111111111 <br>
11111111111 <br>
</div>
</div>
</template>
<script>
export default {};
</script>
<style scoped>
/* 第一种 flex */
.father {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.son {
width: 100px;
background-color: #ccc;
}
/* 第二种 transform+absolute */
.father {
height: 100vh;
position: relative;
}
.son {
width: 100px;
background-color: #ccc;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style> |
.father{
display: flex;
justify-content: center;
align-items: center;
} 2: 利用 .father{
position: relative;
}
.children{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
} |
第二种子元素需要有固定高宽 |
1,flex |
CodePen 地址:https://codepen.io/Konata9/pen/OJLbMyv?editors=1100 |
万能定位:position各个坐标全部为0,margin: 0 auto |
|
第93天 写出div在不固定高度的情况下水平垂直居中的方法?
The text was updated successfully, but these errors were encountered: