Div width 100% minus fixed amount of pixels

后端 未结 10 2066
猫巷女王i
猫巷女王i 2020-11-28 17:57

How can I achieve the following structure without using tables or JavaScript? The white borders represent edges of divs and aren\'t relevant to the question.

10条回答
  •  清酒与你
    2020-11-28 18:25

    Maybe I'm being dumb, but isn't table the obvious solution here?

    .parent{ display: table; width 100%; } .fixed { display: table-cell; width: 150px; } .stretchToFit{ display: table-cell; vertical-align: top}

    Another way that I've figured out in chrome is even simpler, but man is it a hack!

    .fixed{ 
       float: left
    }
    .stretchToFit{
       display: table-cell;
       width: 1%;
    }
    

    This alone should fill the rest of the line horizontally, as table-cells do. However, you get some strange issues with it going over 100% of its parent, setting the width to a percent value fixes it though.

提交回复
热议问题