【问题标题】:Html three divs side by side with same heightHtml三个div并排具有相同的高度
【发布时间】:2017-10-25 01:26:35
【问题描述】:

我正在尝试并排设置三个 div,每个 div 的宽度和高度都相等。 我无法在最右边的 div 中删除多余的空间。如果我将它的 margin-right 设置为 0,最右边的 div 会变得比其他两个大。

这里是fiddle

CSS:

 .recordpopup {
        position: fixed;
        z-index: 10000;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        background-color: rgba( 0, 0, 0, .8);
        background-position: 50% 50%;
        background-repeat: no-repeat;
        display: block;
    }

    .recordpopup .retry {
        background-color: black;
        border: 1px solid white;
        xborder-radius: 8px;
        box-sizing: border-box;
        color: white;
        font-family: ProximaNova-Regular;
        font-size: 16px;
        font-weight: bold;
        xheight: 50px;
        margin-left: auto;
        margin-right: auto;
        padding-top: 0px;
        position: relative;
        text-align: center;
        top: 30%;
        width: 40%;
        z-index: 15000;
        border-radius: 8px;
        padding: 20px 10px;
        background-image: url('images/gray_bar.png');
        background-repeat: repeat-x;
        background-color: white;
    }

    #product-wrapper {
        overflow: hidden;
        margin-top: 25px;
    }

    .product {
        float: left;
        width: 33%;
        display: table-cell;
        width: 33.33333333%;
    }

    .product .container {
        margin-right: 10px;
        padding: 10px;
        background-color: #000;
    }

    .product .container img {
        display: block;
        margin: 0 auto;
        width: 100%;
    }

    #closeRecord {
        background: black none repeat scroll 0 0;
        border: 2px solid white;
        border-radius: 50%;
        color: white;
        cursor: pointer;
        height: 25px;
        right: -15px;
        left: right;
        position: absolute;
        top: -10px;
        width: 25px;
    }

HTML:

<div class="recordpopup">
        <div class="retry">
            <div id="closeRecord">x</div>
            <div style="width: 100%;text-align: left;margin: 5px 0;font-size: 12px;color:#333;"><span class="TitleText">Lorem Ipsum Lorem Ipsum</span> </div>
            <div id="product-wrapper">
                <div class="product">
                    <div class="container">
                        <img src="images/circle.png">
                        <p>Dummy</p>
                    </div>

                </div>
                <div class="product">
                    <div class="container">
                        <img src="images/circle.png">
                        <p>Dummy</p>
                    </div>
                </div>
                <div class="product">
                    <div class="container">
                        <img src="images/circle.png">
                        <p>Dummy</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

【问题讨论】:

标签: html css


【解决方案1】:

这是我的解决方案。

关键是删除margin-right: 10px并添加

    .product:nth-child(1) .container{
      margin-right:5px;
    }
    .product:nth-child(2) .container{
      margin: 0 5px 0 5px;
    }
    .product:nth-child(3) .container{
      margin-left: 5px;
    }

JSFiddle ===> https://jsfiddle.net/kjkk3f9d/1/

【讨论】:

    【解决方案2】:

    margin-right: 10px 正在推出您的 div,将其替换为 margin: 0 5px 以提供统一的外观

    .product .container {
                margin: 0px 5px;
                padding: 10px;
                background-color: #000;
            }
    

    https://jsfiddle.net/kjkk3f9d/3/

    【讨论】:

      【解决方案3】:

      看看我的小提琴:

      https://jsfiddle.net/kjkk3f9d/2/

      重要的样式是

          #product-wrapper {
              overflow: hidden;
              margin-top: 25px;
              display: flex;
              justify-content: space-between;
          }
      
          .product {
              flex-basis:0;
              flex: 1 1 auto;
              margin: 5px;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-24
        • 1970-01-01
        • 2022-09-30
        • 2010-11-15
        • 2016-06-29
        相关资源
        最近更新 更多