如何将这两个元素布局使用CSS在同一行上?

发布于 2025-01-29 17:10:09 字数 1240 浏览 0 评论 0原文

我在Angular HTML页面中有以下代码,我需要使标签位于下拉列表

<div *ngIf="this.userRole == 'myrequests' " class="col-2" [ngClass]="{ 'd-none': view != 'list' }" id="statusFilter">
      <label class="font-weight-bold text-secondary" for="statusFilter">Filter By Status:</label>
      <select style="display: inline-block ;"
        name="statusFilter"
        [(ngModel)]="statusFilter"
        class="form-control"
        (change)="setStatusFilter()">
        <option  [value]="'none'" disabled selected><strong> Choose Filter: </strong></option> 
        <option   *ngFor="let status of statuses" [value]="status.name">
            {{ status.name }}
        </option>
    </select>
</div>

typescript文件旁边的标签具有数组:

  statuses = [
    { id: 0, name: "All" },
    { id: 1, name: "Approved" },
    { id: 2, name: "Created" },
    { id: 3, name: "Rejected" },
    { id: 4, name: "Cancelled" },
    { id: 5, name: "Approval Pending" },
  ];

所需的布局我想在同一行上,

如本图像所示的当前情况:

I have the following code in Angular html page which i need to make the label sit next to the dropdown list

<div *ngIf="this.userRole == 'myrequests' " class="col-2" [ngClass]="{ 'd-none': view != 'list' }" id="statusFilter">
      <label class="font-weight-bold text-secondary" for="statusFilter">Filter By Status:</label>
      <select style="display: inline-block ;"
        name="statusFilter"
        [(ngModel)]="statusFilter"
        class="form-control"
        (change)="setStatusFilter()">
        <option  [value]="'none'" disabled selected><strong> Choose Filter: </strong></option> 
        <option   *ngFor="let status of statuses" [value]="status.name">
            {{ status.name }}
        </option>
    </select>
</div>

typescript file has the array:

  statuses = [
    { id: 0, name: "All" },
    { id: 1, name: "Approved" },
    { id: 2, name: "Created" },
    { id: 3, name: "Rejected" },
    { id: 4, name: "Cancelled" },
    { id: 5, name: "Approval Pending" },
  ];

The desired layout I want to be on the same line

the current situation as shown in this image:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我只土不豪 2025-02-05 17:10:09

对于父母,请使用FlexBox:

display: flex;
align-items: center;

For the parent class, use flexbox:

display: flex;
align-items: center;
若有似无的小暗淡 2025-02-05 17:10:09

您可以给标签一个显示:内联块;同样。

或者,您可以将标签和两者都放在不同的div中,并给那些Div的一定宽度。

You could give the label a display: inline-block; aswell.

Or you could put the label and both in a different div and give those div's a certain width.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文