html - Changing the length of a shape based on a given value
问题描述
I have designed a card-shaped rectangle, that has an inside integer value which is obtained from an angular module/class/type script.... I want to change the height of the shape based on the inside value: the larger the value, the longer the height of the rectangle.
so far, this is my code
<div class = "card">
<div class="content">
<p id = "name">
{{Card.lesson.Name}}
</p>
<p id = "time">
{{Card.duration.Hours}}
<span>
:
{{Card.duration.Minutes}}
</span>
</p>
</div>
<div class = "shape">
</div>
</div>
.card
{
width : 100px;
height : 150px;
background :#FFFFFF;
border: 1px solid #EEE2FA;
border-radius : 10px;
position: relative;
}
#name
{
position: relative;
text-align:center;
font-size:15px;
top:30px;
}
#time
{
position: relative;
text-align:center;
font-size:15px;
top:50px;
}
.shape
{
position: absolute;
display: block;
height:85%;
width: 3px;
background-color: blue;
padding-top: 0px;
top: 10px;
border-radius: 4px;
right: auto;
left: 8px;
padding-left: 8px;
}
The problem is, I have no Idea how to do so. how can I possibly relate Card.Duration.Hours to the height of the card?
解决方案
你可以ngStyle
这样做
你的代码将是这样的:
<div class = "card" [ngStyle]="{'height': Card.duration.Hours + 'px'}">
<div class="content">
<p id = "name">
{{Card.lesson.Name}}
</p>
<p id = "time">
{{Card.duration.Hours}}
<span>
:
{{Card.duration.Minutes}}
</span>
</p>
</div>
<div class = "shape">
</div>
</div>
您可以指定自己的单位而不是px
希望能帮助到你。
推荐阅读
- doxygen - Doxygen,仅文件验证
- json - 如何使用 Jersey 2.27 反序列化客户端站点上的 JSON 数组
- c# - 如何返回上一页,并保留上一页内容 WPF
- javascript - Javafx webEngine executescript()无法发送多行字符串
- neo4j - 获取连接到每个节点的关系计数 - neo4j
- c# - 如何防止在 UWP 中自动关闭软输入面板?
- javascript - node.js v10.0.0 搞砸 gulp
- css - Angular ng-style 不适用于 FontAwesome 图标
- sorting - std中是否存在计数排序:STL中的排序?
- asana - 如何将默认“受让人”设置为特定用户