在Chrome中显示表格和表格单元格错误

时间:2013-08-09 09:35:14

标签: css css-tables

HTML

<div class="circle">
  <div class="content">
      <span><h3>heading</h3><p>slogan goes here</p></span>
  </div>
</div>

CSS

.circle {
  position: relative;
  width: 0;
  height: 0;
  padding: 20%;
  margin: 1em auto;
  border-radius: 50%;
  background: #a7cd80;
}

.content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: table;
  overflow: hidden;  
}
.content span{
  display: table-cell;
  vertical-align: middle;
  text-align: center;
 }
h3{
    line-height: 1px;
}

此代码仅适用于Firefox,但不适用于Chrome等。文本在Firefox中显示为表格单元格,但在其他文本中,文本仅在firefox中以水平和垂直方向居中显示。

demo

你可以看到这个 enter image description here

3 个答案:

答案 0 :(得分:3)

这是因为你给.circle宽度和高度为0,这意味着对象内部实际上没有空间,所以当你给出跨度的宽度和高度为100%时,它是实际宽度和高度将为0

如果你给你的圆圈一个实际的宽度和高度,而不是使用填充形状,那么它应该工作

http://jsfiddle.net/pj3u5/

答案 1 :(得分:1)

使用<div>设置内容样式,如demo

所示

答案 2 :(得分:-1)

您必须为IE和Chrome使用不同的样式。不幸的是,某些样式在不同的浏览器中表现不同。