Set div to have its siblings width

后端 未结 8 1507
猫巷女王i
猫巷女王i 2020-12-05 09:34

I\'m looking for a CSS solution to the following:-

相关标签:
8条回答
  • 2020-12-05 10:33

    Not sure if I understood what you are trying to do, but looks like setting a 100% width to the last div should work:

    <div style="width:100%;"> 
    

    BTW the style in the first div is not well defined, you should use a colon instead of a equal sign in the properties definition:

    <div style="display:inline;">
    
    0 讨论(0)
  • 2020-12-05 10:34

    Floats and tables are so 2000 and late. With today's browsers we can make the two sibling DIVs match each other's width, regardless which is bigger/smaller.

    Here's a Flexbox solution fit for 2016:

    .wrapper {
      display: inline-block;
    }
    
    .parent {
      display: flex;
      flex-direction: column;
    }
    
    /* For visualization */
    .child {
      border: 1px solid #0EA2E8;
      margin: 2px;
      padding: 1px 5px;
    }
    <div class="wrapper">
      <div class="parent">
        <div class="child">Child number one</div>
        <div class="child">Child #2</div>
      </div>
    </div>

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