How to make CSS width to fill parent?

前端 未结 5 482
天命终不由人
天命终不由人 2020-12-13 11:32

I am sure this problem has been asked before but I cannot seem to find the answer.

I have the following markup:

5条回答
  •  醉酒成梦
    2020-12-13 12:11

    So after research the following is discovered:

    For a div#bar setting display:block; width: auto; causes the equivalent of outerWidth:100%;

    For a table#bar you need to wrap it in a div with the rules stated below. So your structure becomes:

    This way the table takes up the parent div 100%, and #barWrap is used to add borders/margin/padding to the #bar table. Note that you will need to set the background of the whole thing in #barWrap and have #bar's background be transparent or the same as #barWrap.

    For textarea#bar and input#bar you need to do the same thing as table#bar, the down side is that by removing the borders you stop native widget rendering of the input/textarea and the #barWrap's borders will look a bit different than everything else, so you will probably have to style all your inputs this way.

    提交回复
    热议问题