我在屏幕中央有一个带有标题的模式。 该 header 必须包含标题和关闭它的按钮。
--------------------------------
| (close)|
| Text |
| |
--------------------------------
所以基本上我有两个要求:
- 标题中的每个文本都必须垂直居中。
- 能够将“(关闭)”放置在 Angular 落的标题附近。
现在我的所有内容都垂直居中,但我将元素放在 ma 堆的标题中:
--------------------------------
| |
| Text |
| (close) |
| |
--------------------------------
.modal-payment__wrapper { // <- this is the whole box
max-width: 50%;
width: 500px;
height: 200px;
background: white;
font-family: 'Lato', 'sans-serif';
}
.modal__header { // <- this is the header
display: flex;
justify-content: center;
flex-direction: column;
width: 100%;
height: 50px;
background-color: black;
color: white;
font-size: 16px;
padding-left: 20px;
}
.modal__header__title { // <- this is "text"
text-transform: uppercase;
letter-spacing: 2px;
font-size: 1.7em;
padding: 10px;
flex-grow: 0;
flex-srhink: 0;
flex-basis: auto;
align-self: auto;
}
<div class="modal-payment__background">
<div class="modal-payment__wrapper">
<div class="modal__header">
<div>
Text
</div>
<div class="modal__header__x"
@click="closeModal">
x
</div>
</div>
<div class="modal__body">
我错过了什么?
最佳答案
提供的代码中有不少错误,但我认为这就是您所需要的。我不得不删除 @click,因为这里无法识别它。
.modal-payment__wrapper {
max-width: 50%;
width: 500px;
height: 200px;
background: white;
font-family: 'Lato', 'sans-serif';
}
.modal__header {
width: 100%;
height: 50px;
background-color: black;
color: white;
font-size: 16px;
padding-left: 20px;
position: relative;
display: flex;
align-items: center;
}
.modal__header__title {
text-transform: uppercase;
letter-spacing: 2px;
font-size: 1.7em;
}
.modal__header__x {
position: absolute;
right: .5em;
top: 0;
}
<div class="modal-payment__background">
<div class="modal-payment__wrapper">
<div class="modal__header">
<div class="modal__header__title">
Text
</div>
<div class="modal__header__x">
x
</div>
</div>
</div>
</div>
关于html - flexbox:垂直居中两个div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45057923/