html - css 简单布局与 flex

标签 html css flexbox

您好,我正在尝试为我的应用程序的部分 UI 部分实现以下外观,

enter image description here

正如你所看到的,我也将按钮居中放置在一个元素的中间,它们之间有一个很好的空间,我试图用下面的代码实现这一点

<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;
        }
    }
}

但是这导致了以下结果,

enter image description here

如您所见,我在元素中放置了按钮,但它们占据了父元素宽度的整个宽度,而不是居中。

最佳答案

只需从按钮中删除 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>

关于html - css 简单布局与 flex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39163835/

相关文章:

html - 将内容左对齐的 div 居中

javascript - 使用 .innerHTML 时 HTML 标签损坏

javascript - 加载图像后调整 HTML Canvas 大小

html - 底部带有三 Angular 形的引用气泡

html - 如何使 Bootstrap 表单字段水平

html - 我网站的全宽导航栏

javascript - 单击 anchor 内的 div 时取消 anchor

html - 从wordpress站点删除右侧的空白

css - 具有图像重叠的 Flexbox 布局

html - css flexbox布局 - 如何滚动内部容器?