Setting height: 100% on my label element doesn't work

前端 未结 2 1785
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 07:34

I tried to set height: 100%; in the label, but it didn\'t work. Why not?

相关标签:
2条回答
  • 2020-11-27 07:44

    In this case I believe your div's height is being determined by the height of the tallest element within it: the text-area. (Reference) Perhaps you want to figure out how many pixels tall your text-area is (for instance this can be done with Firebug, or IE or Chrome's developer tools), and then set your label to that same height.

    I'd also explicitly set that height for the text-area to be sure it's the same in all browsers.


    The reason height: 100% isn't working as you expect is that the parent element has a height of auto. This results in your label also getting a computed height of auto.

    <percentage> Specifies a percentage height. The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to 'auto'.
    (Reference)

    0 讨论(0)
  • 2020-11-27 07:48

    You have height set to 100% but 100% of what? It's always the parent of that element so what is the parent's height set to? If it's not set to anything then the browser has nothing to reference.

    0 讨论(0)
提交回复
热议问题