如何根据其他元素的CSS属性设置CSS属性

时间:2019-06-01 19:09:31

标签: html css ionic-framework

我正在使用离子4,并且想要在其他元素上方设置一些遮罩元素。 我的mask元素是我要设置在ion-tab-bar上方的固定图像-这意味着我希望我的图像“底部” css属性将与ion-tab-bar css“ height”属性相同值。

我已经在标签页中尝试过此操作:

ionViewDidEnter() {
    document.getElementById('mask').style.bottom = document.getElementById('tabsbar').style.height;
}

但是style属性返回了空字段...

还有其他方法吗?也许可以使用ngStyle?

2 个答案:

答案 0 :(得分:0)

您可以使用jquery方式:

# A tibble: 6 x 7
  year  v1    v2    v3    v4    v5    v6   
  <chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 1931  1     5.0   0.6   11    78.4  43.4 
2 1931  2     6.7   0.7   7     48.9  63.6 
3 1931  4     10.4  3.1   3     44.6  110.1
4 1931  5     13.2  6.1   1     63.7  167.4
5 1931  6     15.4  8.0   0     87.8  150.3
6 1931  7     17.3  10.6  0     121.4 111.2
function hallo(){
    $("#num1").css("bottom", $("#num2").css("height")); 
}
#num1{
position: absolute;
bottom: 100px;
background-color: red;
padding: 15px;
width: 100px;
height: 50px;
}
#num2{
position: absolute;
top: 0;
left: 100px;
background-color: green;
padding: 15px;
width: 100px;
height: 150px;
}

答案 1 :(得分:0)

已解决:

ionViewDidEnter() {

  document.getElementById('mask').style.bottom = document.getElementById('tabsbar').getBoundingClientRect().height+'px';

}