Keeping parent div to width and height of wrapping children

前端 未结 3 744
粉色の甜心
粉色の甜心 2021-01-26 02:16

I am building a simple calendar. I am wanting the months to wrap responsively on screen, and the parent container to keep the width and height of its children. For example, if t

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-26 02:52

    Your code is almost perfect, just apply box-sizing:border-box; to .cal and .month elements. because border width is excluded from width without using border-box.

    I think that's not possible with css, i could find a best possible solution for your answer in my following code

    
        
          
        
        
        
    Jan
    Feb
    Mar
    Apr
    May
    Jun
    Jul
    Aug
    Sep
    Oct
    Nov
    Dec

    We can just make it a little better looking by centering all children, because the reserved space on first line couldn't be deducted from parent's width.

提交回复
热议问题