【发布时间】:2021-03-14 03:55:50
【问题描述】:
我正在开发一个界面,该界面允许用户更改按钮位置并在按钮下写入标签文本。 我的问题是,标签并不总是在按钮下方居中,这取决于文本标签的大小和字母数,
这是我的 CSS 类
.button-wrapper {
display: inline-block;
max-width: 80px;
text-align: center;}
.button-wrapper > button {
display: block;
height: 75px;
width: 75px;
border-radius: 50%;
position: relative;
border: 1px solid gray;
text-align: center;
:active {border: 3px solid yellow;}
:hover{border: 2px solid red;}}
.button-wrapper > label {
display: block;
position: relative;
font-size: 14px;
margin:0 auto; left:0; right:0;
padding: 3px;}
这是我的html代码
<div class="button-wrapper">
<button
[class.btn-primary]="true"
[style.color]="buttonStyle.labeLFontColor"
[ngStyle]="{'margin-left': bar.accessPosition+'%','font-style': buttonStyle.labeLFontFamily, 'font-size.px':buttonStyle.labeLFontSize, 'font-weight':buttonStyle.labeLFontWeight,
'background-color': buttonStyle.backgroundColor, 'font-family': buttonStyle.labeLFontFamily, 'border-color': buttonStyle.borderColor,
'border': buttonStyle.borderSize+'px solid', 'background':'url(assets/showcase/images/accessButtons/' + bar.accessBackImage+') white center center no-repeat',
'background-size': '100% 75px'}">
</button>
<label *ngIf="useLabel" [ngStyle]="{'margin-left': bar.accessPosition+'%','font-style': buttonStyle.labeLFontFamily, 'font-size.px':buttonStyle.labeLFontSize, 'font-weight':buttonStyle.labeLFontWeight,'font-family': buttonStyle.labeLFontFamily }">{{accessLabel}}</label>
</div>
正如您所见,标签大小是动态的,标签文本也有一个输入来编写文本... 那么,我怎样才能将标签固定为始终居中并低于用户所写的任何内容。 谢谢。
【问题讨论】:
-
你能分享一个 Stackblitz 的例子吗?
-
当然,这是一个 stackblitz 链接:angular-ivy-xq4wal.stackblitz.io
标签: html css angular dynamic label