将width
和height
设定在固定水平并不是最好的 Select .
在styles.scss
中添加以下css:
.mat-badge-content {
width: auto !important; // Set the width to auto
height: auto !important; // Set the height to auto
min-width: 22px; // But the width should be at least 22px (in case the number is 99 or less)
min-height: 22px; // But the height should be at least 22px (in case the number is 99 or less)
aspect-ratio: 1/1; // Keep the circle shape
display: flex; // Required in order for align-items and justify-content to work
align-items: center; // Center the number vertically
justify-content: center; // Center the number horizontally
padding: 2px; // Add a bit of padding so that the number is not placed all the way to the border of the circle
}
屏幕截图:
请看live demo.