【发布时间】:2019-05-06 10:40:55
【问题描述】:
使用 Angular、Angular Material 和 Angular Flex-Layout,我创建了一组样式类似于卡片或图块的链接。当链接未悬停时,将显示链接的图标和标题。悬停时,图标和标题不再显示并替换为信息文本。
对于具有大量信息文本的项目,这种状态变化会导致项目的高度增加。
我可以通过使用像素对min-height 进行硬编码来解决此问题。但是,如果我尝试使用百分比,例如 110%,则链接的大小不会发生变化。对于名为 .container 的链接周围的 div 也是如此。
摘录如下:
<div class="container" fxLayout fxLayoutAlign="center" fxLayoutGap="10px">
<a mat-flat-button color="primary" fxFlex href="https://example.com/footprints">
<div class="hoverOff"><fa-icon [icon]="faToolbox"></fa-icon>Broken</div>
<div class="hoverOn">Is your request causing an impact to a business-critical function, which is impacting daily production?</div>
</a>
<a mat-flat-button color="primary" fxFlex href="https://example.com/divisions/dev/Lists/Requests/NewForm.aspx?isProject=Yes">
<div class="hoverOff"><fa-icon [icon]="faPuzzlePiece"></fa-icon>Project</div>
<div class="hoverOn">Is your request a new product or service?<br>
Requires and RFI or RFP?<br>
Requires more than 500 or more internal resource hours<br>
Necessitates a cost greater then $100,000?<br>
New banking center or remodel?<br>
New Partnership, divestiture or branch closure?
</div>
</a>
</div>
<style>
.mat-flat-button {
white-space: normal;
line-height: normal;
}
a {
color: white !important;
display: flex;
justify-content: center;
align-items: center;
}
fa-icon {
display: block;
font-size: 75px;
}
.mat-primary {
background-color: #00539B !important;
}
a .hoverOn {
display: none;
}
a:hover .hoverOn {
display: block;
}
a:hover .hoverOff {
display: none;
}
</style>
I have created an example of this on StackBlitz.
如何在不对像素进行硬编码的情况下解决这种高度变化?
【问题讨论】:
-
@Marshal 未切断。我希望能够以比使用像素更好的方式设置链接高度。似乎不是解决悬停时大小变化的一种非常安全的方法。
标签: css angularjs flexbox angular-material angular-flex-layout