How to prevent inline-block divs from wrapping?

前端 未结 2 1196
滥情空心
滥情空心 2020-12-24 04:36

jsFiddle demo

I want the divs to:

  • Wrap their content.
  • Stay in their originally associated line, esse
相关标签:
2条回答
  • 2020-12-24 04:58

    This will stop text wrapping, and keep it inline

    .leftContent { float: left; }
    .rightContent { overflow: hidden; }
    
    0 讨论(0)
  • 2020-12-24 05:08

    Add white-space: nowrap; to your .layout style declaration.

    This will do exactly what you need: preventing the divs from wrapping.

    Watch the

    jsFiddle demo

    or run the following snippet full screen and resize it:

    .layout {
           white-space : nowrap; /* this does the trick */
              overflow : hidden; /* this prevents the grey divs from overflowing */
        vertical-align : top;
         border-radius : 15px;
               display : inline-block;
    }
    
    .layoutbacking {
        border-radius : 15px;
           background : #CCCCCC;
              padding : 5px;
               margin : 5px;
    }
    <div class="layout" style="background: #222222; width: 100%">
        <div>
            <div class="layout layoutbacking">
                <table>
                    <tr>
                        <th>header 1</th>
                        <th>header 2</th>
                        <th>header 3</th>
                        <th>header 4</th>
                    </tr>
                    <tr>
                        <td>data 1</td>
                        <td>data 2</td>
                        <td>data 3</td>
                        <td>data 4</td>
                    </tr>
                    <tr>
                        <td>data 1</td>
                        <td>data 2</td>
                        <td>data 3</td>
                        <td>data 4</td>
                    </tr>
                    <tr>
                        <td>data 1</td>
                        <td>data 2</td>
                        <td>data 3</td>
                        <td>data 4</td>
                    </tr>
                </table>
            </div>
            <div class="layout">
                <div class="layout layoutbacking">
                    <table>
                        <tr>
                            <th>header 1</th>
                            <th>header 2</th>
                            <th>header 3</th>
                            <th>header 4</th>
                        </tr>
                        <tr>
                            <td>data 1</td>
                            <td>data 2</td>
                            <td>data 3</td>
                            <td>data 4</td>
                        </tr>
                    </table>
                </div>
                <br />
                <div class="layout layoutbacking">
                    <table>
                        <tr>
                            <th>header 1</th>
                            <th>header 2</th>
                            <th>header 3</th>
                            <th>header 4</th>
                        </tr>
                        <tr>
                            <td>data 1</td>
                            <td>data 2</td>
                            <td>data 3</td>
                            <td>data 4</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div>
            <div class="layout layoutbacking">
                <table>
                    <tr>
                        <th>header 1</th>
                        <th>header 2</th>
                        <th>header 3</th>
                        <th>header 4</th>
                    </tr>
                    <tr>
                        <td>data 1</td>
                        <td>data 2</td>
                        <td>data 3</td>
                        <td>data 4</td>
                    </tr>
                </table>
            </div>
            <div class="layout layoutbacking">
                <table>
                    <tr>
                        <th>header 1</th>
                        <th>header 2</th>
                        <th>header 3</th>
                        <th>header 4</th>
                    </tr>
                    <tr>
                        <td>data 1</td>
                        <td>data 2</td>
                        <td>data 3</td>
                        <td>data 4</td>
                    </tr>
                </table>
            </div>

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