如何对齐DIV与Mat-Expansion-Panel-Header?

发布于 2025-01-24 04:31:45 字数 1744 浏览 4 评论 0原文

我被Angular的matexpansionModule所困。 在Mat-Expansion-Panel-Header部分中,我想显示一个图像和简短描述。 但是,图像和描述不会自动适应该部分。

<mat-expansion-panel>
    <mat-expansion-panel-header>
        <div class="msg-header-img">
            <img [src]="picture" alt="pic description" />
        </div>
        <div class="msg-header-description">
            <h4>Hello</h4>
            <h6>{{ userName }}</h6>
        </div>
    </mat-expansion-panel-header>
    <p>some content</p>
</mat-expansion-panel>

如何正确地对此进行样式,以便在扩展的标题部分正确渲染图像和描述?

编辑: style-sheet:

mat-expansion-panel {
    background-color: blueviolet;
    color: white;
    position: absolute;
    top: 0;
    right: 0;
    width: 25%;
}

.msg-header-img {
    border-radius: 50%;
    width: 40px;
    margin-top: 10px;
    padding-right: 10px;
    background-color: rgb(72, 72, 97);
}

.msg-header-description {
    width: auto;
    float: left;
    margin-top: 10px;
}

.msg-header-description h4 {
    font-size: 16px;
    width: 100%;
    color: #fff;
}

.msg-header-description h6 {
    font-size: 10px;
    line-height: 2px;
    color: #fff;
}

mat-expansion-panel-header {
    background-color: red;
}

“在此处输入图像描述”

我希望它看起来像这样:

I am stucked with the MatExpansionModule from Angular.
In the mat-expansion-panel-header part, I would like to display an image and a short description.
However, the image and description do not automatically adapt to the section.

<mat-expansion-panel>
    <mat-expansion-panel-header>
        <div class="msg-header-img">
            <img [src]="picture" alt="pic description" />
        </div>
        <div class="msg-header-description">
            <h4>Hello</h4>
            <h6>{{ userName }}</h6>
        </div>
    </mat-expansion-panel-header>
    <p>some content</p>
</mat-expansion-panel>

How can this be styled correctly so the image and description is rendered correctly in the header part of the expansion?

Edit:
style-sheet:

mat-expansion-panel {
    background-color: blueviolet;
    color: white;
    position: absolute;
    top: 0;
    right: 0;
    width: 25%;
}

.msg-header-img {
    border-radius: 50%;
    width: 40px;
    margin-top: 10px;
    padding-right: 10px;
    background-color: rgb(72, 72, 97);
}

.msg-header-description {
    width: auto;
    float: left;
    margin-top: 10px;
}

.msg-header-description h4 {
    font-size: 16px;
    width: 100%;
    color: #fff;
}

.msg-header-description h6 {
    font-size: 10px;
    line-height: 2px;
    color: #fff;
}

mat-expansion-panel-header {
    background-color: red;
}

enter image description here

I want it to look something like this:
enter image description here

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

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

发布评论

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

评论(1

优雅的叶子 2025-01-31 04:31:45

您的布局是错误的。您还应该使用Mat-Panel-title和Mat-Panel-Description来管理一些责任,以便您可以简化:

<mat-expansion-panel>
    <mat-expansion-panel-header>
        <mat-panel-title class="msg-header-img">
            <img [src]="picture" alt="pic description" />
        </mat-panel-title>
        <mat-panel-description class="msg-header-description">
            <h4>Hello</h4>
            <h6>{{ userName }}</h6>
        </mat-panel-description>
    </mat-expansion-panel-header>
    <p>some content</p>
</mat-expansion-panel>
mat-expansion-panel {
  background-color: blueviolet;
  color: white;
}

.msg-header-img {
  flex-grow: 0;
}

.msg-header-img img {
  width: 40px;
}

.msg-header-description {
  flex-direction: column;
  align-items: flex-start;
  color: #fff;
}

.msg-header-description h4 {
  font-size: 16px;
  margin: 0;
}

.msg-header-description h6 {
  font-size: 10px;
  margin: 0;
}

Your layout is wrong. You should also use mat-panel-title and mat-panel-description to manage some of the responsibility so that you can simplify:

<mat-expansion-panel>
    <mat-expansion-panel-header>
        <mat-panel-title class="msg-header-img">
            <img [src]="picture" alt="pic description" />
        </mat-panel-title>
        <mat-panel-description class="msg-header-description">
            <h4>Hello</h4>
            <h6>{{ userName }}</h6>
        </mat-panel-description>
    </mat-expansion-panel-header>
    <p>some content</p>
</mat-expansion-panel>
mat-expansion-panel {
  background-color: blueviolet;
  color: white;
}

.msg-header-img {
  flex-grow: 0;
}

.msg-header-img img {
  width: 40px;
}

.msg-header-description {
  flex-direction: column;
  align-items: flex-start;
  color: #fff;
}

.msg-header-description h4 {
  font-size: 16px;
  margin: 0;
}

.msg-header-description h6 {
  font-size: 10px;
  margin: 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文