8

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

这是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;
  }
4

1 回答 1

3

要实现水平对齐,您需要对标记进行一些调整并使用 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>

于 2020-02-16T18:30:15.660 回答