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居中方法总结 #34

Open
ClarenceC opened this issue Dec 13, 2017 · 0 comments
Open

css居中方法总结 #34

ClarenceC opened this issue Dec 13, 2017 · 0 comments
Labels
CSS CSS 的知识点

Comments

@ClarenceC
Copy link
Owner

ClarenceC commented Dec 13, 2017

1. 设置子元素宽度,margin:0 auto;

2. 父类设置display:table, 子类设置display:table-cell,vertical-align: middle;

3. 父类设置position:relative, (子类不定宽)

     子类设置position: absolute,
     top:0;
     right:0;
     bottom:0;
     left:0;
     margin: auto;
     子类设置宽度

4. 父类设置text-align:center (子类不定宽)

      父类设置 before 空白区域居中
                     content: '';
                     display: inline-block;
                     height: 100%;
                     vertical-align: middle;
       子类:display: inline-block;

5. css3 flex (子类不定宽)

      父类设置:
                    display: flex;
                    align-items: center;
                    justify-content: center;

6.设置position: fixed,设置

        top: 0;
        right:0;
        bottom:0;
        left: 0;
        margin: auto;
        width: 300px;
        height: 200px;

7. translate (子类不定宽)

      父类设置
       position: relative,
      子类设置
       position: absolute,
       top: 50%;
       left: 50%;
       transform: translate(-50%, -50%)

8.Float 浮云居中

父类
float:left;
width:100%;
overflow:hidden;
position:relative;

子类
clear:left;
float:left;
position: relative;
left:50%;/整个分页向右边移动宽度50%/
text-align:center;

样版例子 地址

@ClarenceC ClarenceC added the CSS CSS 的知识点 label Mar 21, 2018
@ClarenceC ClarenceC reopened this Mar 21, 2018
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

1 participant