表格单元格的内容大小不同

时间:2017-04-27 23:47:19

标签: html css internet-explorer internet-explorer-11

我在表格中显示了带有页脚文字的圈数。在所有浏览器中,圆形图像的大小相同,IE11和边缘除外。

这就是我目前所拥有的(对于大型css转储感到抱歉 - 我真的不知道造成这个问题的原因):



.circle-container {
  display: table;
}

.circle {
  display: table-cell;
  table-layout: fixed;
  padding: 40px 20px;
  vertical-align: top;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -moz-osx-font-smoothing: grayscale;
  cursor: pointer;
}

.circle>p {
  display: block;
  width: 100%;
  text-align: center;
  margin: 40px 0 0;
}

.circle>div {
  position: relative;
}

.circle>div:before {
  content: '';
  position: absolute;
  border: #54314E solid 4px;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
  -webkit-transition-property: top, right, bottom, left;
  transition-property: top, right, bottom, left;
  border-radius: 50%;
  z-index: 1;
}

.circle>div>img {
  border-radius: 50%;
  width: 100%;
  height: auto;
}

.circle:hover>div:before,
.circle:focus>div:before,
.circle:active>div:before,
.circle.active>div:before {
  top: -15px;
  right: -15px;
  bottom: -15px;
  left: -15px;
}

<div class="circle-container">
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
    <p><b>Corporate &amp; <br>Institutional <br>Banking</b></p>
  </div>
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
    <p><b>Global <br>Transactional <br>Solutions &amp; <br>Client Experience</b></p>
  </div>
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
    <p><b>Financial Markets</b></p>
  </div>
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
    <p><b>International</b></p>
  </div>
</div>
&#13;
&#13;
&#13;

我注意到,当我删除圈子下的文字时,问题并不明显:

&#13;
&#13;
.circle-container {
  display: table;
}

.circle {
  display: table-cell;
  table-layout: fixed;
  padding: 40px 20px;
  vertical-align: top;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -moz-osx-font-smoothing: grayscale;
  cursor: pointer;
}

.circle>p {
  display: block;
  width: 100%;
  text-align: center;
  margin: 40px 0 0;
}

.circle>div {
  position: relative;
}

.circle>div:before {
  content: '';
  position: absolute;
  border: #54314E solid 4px;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
  -webkit-transition-property: top, right, bottom, left;
  transition-property: top, right, bottom, left;
  border-radius: 50%;
  z-index: 1;
}

.circle>div>img {
  border-radius: 50%;
  width: 100%;
  height: auto;
}

.circle:hover>div:before,
.circle:focus>div:before,
.circle:active>div:before,
.circle.active>div:before {
  top: -15px;
  right: -15px;
  bottom: -15px;
  left: -15px;
}
&#13;
<div class="circle-container">
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
  </div>
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
  </div>
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
  </div>
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

我需要保留当前的功能和布局。

注意:知道生成这个圈子时会有多少个圈子,但是p.length == .circle.length。这就是我选择首先使用table-cell的原因,因为我认为这样可以减少手动设置宽度的时间&#34;运行时间&#34;。

1 个答案:

答案 0 :(得分:1)

table-layout:fixed仅适用于display:table而不是table-cell,然后添加width:100%

注意:问题出现在最新的Firefox

&#13;
&#13;
.circle-container {
  display: table;
  table-layout: fixed;
  width:100%
}

.circle {
  display: table-cell;
  padding: 40px 20px;
  vertical-align: top;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -moz-osx-font-smoothing: grayscale;
  cursor: pointer;
}

.circle>p {
  display: block;
  width: 100%;
  text-align: center;
  margin: 40px 0 0;
}

.circle>div {
  position: relative;
}

.circle>div:before {
  content: '';
  position: absolute;
  border: #54314E solid 4px;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
  -webkit-transition-property: top, right, bottom, left;
  transition-property: top, right, bottom, left;
  border-radius: 50%;
  z-index: 1;
}

.circle>div>img {
  border-radius: 50%;
  width: 100%;
  height: auto;
}

.circle:hover>div:before,
.circle:focus>div:before,
.circle:active>div:before,
.circle.active>div:before {
  top: -15px;
  right: -15px;
  bottom: -15px;
  left: -15px;
}
&#13;
<div class="circle-container">
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
    <p><b>Corporate &amp; <br>Institutional <br>Banking</b></p>
  </div>
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
    <p><b>Global <br>Transactional <br>Solutions &amp; <br>Client Experience</b></p>
  </div>
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
    <p><b>Financial Markets</b></p>
  </div>
  <div class="circle">
    <div>
      <img src="http://placehold.it/350x350">
    </div>
    <p><b>International</b></p>
  </div>
</div>
&#13;
&#13;
&#13;