简体   繁体   English

CSS的简单布局与Flex

[英]css simple layout with flex

Hi there I am trying to achive the following look for a partial UI section of my application, 嗨,我正在尝试实现我的应用程序的部分UI部分的以下外观,

在此处输入图片说明

As you can see I too buttons centered in the middle of an element with a nice space between them, I have tried to achive this with the following code 如您所见,我也将按钮居中于一个元素的中间,并在它们之间留出一个不错的空间,我尝试通过以下代码来实现

<div class="modal__footer">  
    <a class="button button--cancel>Skip</a>  
    <a class="button button--confirm>Take the tour!</a>  
</div>

.modal__footer {
    margin-top:30px;
    display:flex;
    .button {
        flex:1;
        &:first-child {
            margin-right:30px;
        }
    }
}

However this has resulted in the following, 但是,这导致了以下情况,

在此处输入图片说明

As you can I have the buttons in the element but they take up the full width of the parent elements width instead of being centered. 可以的话,我在元素中有按钮,但是它们占据了父元素宽度的整个宽度,而不是居中。

Just remove the flex:1 from the buttons and use justify-content:center on the parent. 只需从按钮中删除flex:1 ,然后在父对象上使用justify-content:center

 .modal__footer { margin-top: 30px; display: flex; justify-content: center; } .modal__footer .button { background: #c0ffee; padding: 1em; } .modal__footer .button:first-child { margin-right: 30px; } 
 <div class="modal__footer"> <a class="button button--cancel">Skip</a> <a class="button button--confirm">Take the tour!</a> </div> 

Try this: 尝试这个:

.modal__footer {
    margin-top:30px;
    display:flex;
    text-align:center;
    .button {
        &:first-child {
            margin-right:30px;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM