html按钮大小高度百分比

时间:2016-01-31 21:22:35

标签: html button height percentage

如何将HTML中的按钮大小设置为屏幕的百分比。像素单位有效但百分比没有。 看到这个小提琴:https://jsfiddle.net/3po5o7cb/10/

<button style="width:20%; height:20%"></button>
<button style="width:200px;height:200px"></button>

2 个答案:

答案 0 :(得分:2)

  

要设置百分比高度,其父元素(*)必须具有显式高度。

请参阅this回答。

答案 1 :(得分:0)

您还必须将该按钮的父级高度设为100%。见this solution