css - 我需要每一行具有相同的高度

标签 css

我需要让 div 看起来像表格数据,我使用了 display: table-celldisplay: table 属性,但我没有得到预期的布局。我需要每一行具有相同的高度。 请检查下面的代码

.publishers {
    margin: 45px 0;
    margin-right: 60px;
}

    .publishers .col-xs-6:nth-child(odd) .publisher {
        margin-right: -10px;
    }

    .publishers .col-xs-6:nth-child(even) .publisher {
        margin-left: -10px;
    }

    .publishers .publisher {
        background-color: #f1efef;
        margin-bottom: 10px;
    }

        .publishers .publisher .media {
            padding: 10px;
        }

            .publishers .publisher .media .media-left img {
                width: 128px;
                height: 128px;
            }

            .publishers .publisher .media .media-body h3 {
                font-size: 30px;
                font-weight: 400;
            }


/***** my try *****/
.publishers{
display:table;
  }
.publishers .publisher{
  display: table-cell;
  }

  
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>

<section class="publishers">
<div class="row">
<div class="col-xs-6">
                                    <div class="publisher">
                                        <div class="media">
                                            <div class="media-left">
                                                <a style="  height: 131px; display: block;" href="http://www.cengage.com
">
                                                    <img style="  height: auto;" src="Publishers/7726f4a3-b23d-4af1-879d-57da2a567bd1.jpg" alt="...">
                                                </a>
                                            </div>
                                            <div class="media-body">
                                               <a href="http://www.cengage.com
"><h3>Cengage</h3></a>
                                                <p class="description">A company that delivers highly..
</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>

<div class="col-xs-6">
                                    <div class="publisher">
                                        <div class="media">
                                            <div class="media-left">
                                                <a style="  height: 131px; display: block;" href="http://www.elsevier.com
">
                                                    <img style="  height: auto;" src="Publishers/b3723614-ea79-4b24-a9fb-ae0c1da9a3c4.png" alt="...">
                                                </a>
                                            </div>
                                            <div class="media-body">
                                               <a href="http://www.elsevier.com
"><h3>Elsevier </h3></a>
                                                <p class="description">A world’s leading publisher of science and health information serves more than 30 million scientists, students and health and information professionals worldwide
</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
  <div class="col-xs-6">
                                    <div class="publisher">
                                        <div class="media">
                                            <div class="media-left">
                                                <a style="  height: 131px; display: block;" href="http://eu.wiley.com/WileyCDA/Section/index.html 
">
                                                    <img style="  height: auto;" src="Publishers/ff9e4261-36a1-4cd3-bf9c-c169ff8661eb.png" alt="...">
                                                </a>
                                            </div>
                                            <div class="media-body">
                                               <a href="http://eu.wiley.com/WileyCDA/Section/index.html 
"><h3>WILEY</h3></a>
                                                <p class="description">Wiley is a global publisher of print and electronic products, textbooks, and other educational materials, for students both undergraduate and postgraduate, specializing in scientific, technical, and medical books and journals; professional and consumer books and subscription services. Wiley has approximately 22,700 active titles and 400 journals, and publishes 2000 new titles in a variety of print and electronic formats each year
</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
  <div class="col-xs-6">
                                    <div class="publisher">
                                        <div class="media">
                                            <div class="media-left">
                                                <a style="  height: 131px; display: block;" href="https://www.pearson.com/
">
                                                    <img style="  height: auto;" src="Publishers/d18fbae5-1587-4b06-a0e4-8b0b1ec4ab13.jpg" alt="...">
                                                </a>
                                            </div>
                                            <div class="media-body">
                                               <a href="https://www.pearson.com/
"><h3>Pearson</h3></a>
                                                <p class="description">Global leader in educational publishing offers comprehensive range of educational programs, in all subjects, for every age and level of student, from preK-12 through higher education and on into professional life. 
</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
  </div>
  </section>

最佳答案

.publishers .row {
  display: flex;
}

如果你不需要 IE9 和更低版本的支持,你可以使用 flex 默认情况下使用 align-items: stretch 这使得所有的 child 都是全高

关于css - 我需要每一行具有相同的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31292509/

相关文章:

java - YUI 压缩器与 Granule

html - 改变 LI 元素的文本颜色

css - 标题旁边的 float 缩略图

css - 在 Chrome + GWT 中通过 CSS 悬停

javascript - CSS:网站在减少浏览器宽度时看起来不错,但在手机屏幕上减少了一半

javascript - CSS 在表格的列背景颜色和表格中的选定行中禁用输入

javascript - Colorbox的tabindex =“-1”属性可防止在表单字段上进行焦点和键入

PHP包含不同的目录

javascript - 如何使用 div 按钮而不是滚动条滚动

更改元素颜色属性的 JavaScript 代码