Skip to content
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] 第61天 怎样把一个div居中?怎样把一个浮动元素居中?怎样把绝对定位的div居中? #255

Open
haizhilin2013 opened this issue Jun 15, 2019 · 3 comments
Labels
css css

Comments

@haizhilin2013
Copy link
Collaborator

第61天 怎样把一个div居中?怎样把一个浮动元素居中?怎样把绝对定位的div居中?

@haizhilin2013 haizhilin2013 added the css css label Jun 15, 2019
@xn213
Copy link

xn213 commented Jun 16, 2019

主要用到:

  1. text-alin: center;
  2. margin: 0 auto;
  3. position: relative | absolute; left: 50%;
  4. vertical-align: middle;
  5. transform: translate(-50%);

@xjt31012
Copy link

假定是水平居中
div居中:
margin:0 auto;
浮动元素居中(div居中也可以用):
margin-left: 50%; transform: translate(-50%);
绝对定位的div居中:
{ top:0; left:0; bottom:0; right:0; margin: auto; }

@MrZ2019
Copy link

MrZ2019 commented Dec 28, 2020

主要用到:

  1. text-alin: center;
  2. margin: 0 auto;
  3. position: relative | absolute; left: 50%;
  4. vertical-align: middle;
  5. transform: translate(-50%);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css css
Projects
None yet
Development

No branches or pull requests

4 participants