2016-11-16 61 views
1

我有一样的东西:更改继承了高度

.parent { 
    height: 400px 
} 

.child { 
    height: inherit; 
} 

,我需要通过像素更改继承高度 - > 像这样

.child { 
    height: inherit - 10px 
} 

所以child height390px我们案件。 问题是继承高度是一个对象。

任何方式来做到这一点?

回答

0

虽然可以使用计算的,人长的计算之前做这样的事情:

.parent { 
 
    border: 1px solid red; 
 
    height: 100px; 
 
    width: 100px; 
 
    position: relative; 
 
} 
 

 
.child { 
 
    border: 1px solid blue; 
 
    position: absolute; 
 
    bottom: 10px; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
}
<div class="parent"> 
 
    <div class="child"></div> 
 
</div>

+0

谢谢你的回答。我不能使用calc,因为它在手机环境中有一些崩溃。旧的方式为我工作:)非常感谢你 –

5

你可以用calc做到这一点:

.child { 
    height: calc(100% - 10px); 
} 
+0

只是注意,并不完全是跨浏览器兼容的。 – Crowes

+0

@Crowes哪些浏览器不支持? – 2016-11-16 17:25:57

+0

@torazaburo http://caniuse.com/#feat=calc – Crowes