angular - 如何将 mat-card-image 高度设置为 100%?
问题描述
这是代码:app.component.html
<div fxLayout="row">
<mat-card fxLayout="row" fxFlex="80%" class="center space-top">
<mat-card-content fxLayout.gt-sm="row">
<div fxLayout.gt-sm="column" fxFlex.gt-sm="40%">
<img mat-card-image src="../../../assets/background.jpg" alt="background image">
</div>
<div fxLayout.gt-sm="column" fxFlex.gt-sm="50%" class="gutter">
<router-outlet></router-outlet>
</div>
</mat-card-content>
</mat-card>
</div>
CSS部分:
.center {
margin-left: auto;
margin-right: auto;
}
.space-top {
margin-top: 5%;
}
@media only screen and (min-width: 799px){
.gutter {
margin-left: 32px;
}
}
解决方案
好的,实际发生的情况是,我的表单高度大于左侧图像的高度。所以我不得不在图像中添加一些 CSS 属性
img {
height: fit-content; //so that it takes up full space
max-height: 500px !important; // this prevents the image from being extremely big
object-fit: cover;
object-position: center; /* this centers and crops the image so that it doesn't break the aspect ratio */
}
推荐阅读
- sql - 使用执行流程任务将变量值传递到 .bat 文件
- angular - 如何在代码库中找到父组件 - angular 5?
- azure - Azure AD 和 Azure B2C 中的用户和组织管理
- logout - 如何使用 Amazon Cognito 注销终端节点?
- javascript - 基于单选按钮更新元素的 CSS 样式
- mongodb - Mongoose:从混合类型中查找子文档并更新
- reactjs - 如果满足条件如何继续安装?
- java - Android 将传感器中的数据保存在内部存储文件中未找到
- apache-spark - 无法从 pyspark 加载管道模型
- ios - Viewcontroller 在动画完成之前显示