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

一个div在另外一个div横向居中,纵向自定义 #11

Open
deepthan opened this issue Jan 16, 2018 · 0 comments
Open

一个div在另外一个div横向居中,纵向自定义 #11

deepthan opened this issue Jan 16, 2018 · 0 comments

Comments

@deepthan
Copy link
Owner

html

<div class='container'>
    <div class='wrap'>
        <div class='detail'>
           <i class="fa fa-shield" aria-hidden="true"></i>
        </div>
    </div>
</div>

css

.container{
    width: 200px;
    height: 40px;
    position: relative;
    border-bottom: 2px #E5E5E5 solid;
}
.wrap{
    width: 100%;
    height: 30px;
    position: absolute;
    bottom: -21px;
    padding-right: 20px;
}
.detail{
    width: 20px;
    height: 30px;
    margin-left: 50%;
    background: #fff;
    font-size: 19px;
    text-align: center;
    padding-left: 7px;
    color: #0061ae;
}

思路:
.wrap的div和父级一样大小,padding-right为20px,那么它的内部空间还有180,它的一半是90, .detail离左边50%即距离左边90px;加上它的一半10 是100,即位于最外层元素 200的一半。

@deepthan deepthan changed the title 一个div在另外一个div水平居中 一个div在另外一个div横向居中,纵向自定义 Jan 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant