如何才能使这两个项目正确对齐?我试图让它们完全对齐,但调整按钮高度只会使底部离搜索输入的底部更远。我认为这是因为它们的中心不对齐,所以调整高度并不是真正正确的解决方案。

这是HTML
<!-- Search Box and Button-->
<p>Search by company name:</p>
<mat-form-field appearance="outline">
<mat-label>Search</mat-label>
<input matInput placeholder="Search">
</mat-form-field>
<button mat-stroked-button color="primary">Search</button>以下是SCSS:
mat-form-field.mat-form-field {
font-size: 12px;
width: 300px;
}
button.mat-stroked-button {
font-size: 14px;
height: 42px;
margin: 10px;
}发布于 2020-02-17 02:30:16
要实现水平对齐,您需要对标记进行一些调整,并使用flex属性来实现完美对齐。我已经添加了一些div作为父类,但是如果你愿意,你可以将CSS分配给你的代码的实际父类。我已经添加了下面的代码片段,相应地更新HTML和CSS:
.searchcontainer {
text-align:center;
width: 100%;
max-width: 600px;
margin: 0 auto;
}
.searchcontainer .search-part {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
mat-form-field.mat-form-field {
font-size: 12px;
width: 300px;
}
button.mat-stroked-button {
font-size: 14px;
height: 42px;
margin: 10px;
}<div class="searchcontainer">
<p>Search by company name:</p>
<div class="search-part">
<mat-form-field appearance="outline">
<mat-label>Search</mat-label>
<input matInput placeholder="Search">
</mat-form-field>
<button mat-stroked-button color="primary">Search</button>
</div>
</div>
https://stackoverflow.com/questions/60251487
复制相似问题