html - 水平对齐表格内的表格单元格

标签 html css

如何水平对齐此表格单元格中的文本?看起来它向右浮动,我不确定为什么。 https://jsfiddle.net/o06e11o9/

HTML

<div class="affil2">
  <div class="oval2"></div>
  <div class="contents">
    a lorem ipsum dolor sit amet. Donec facilisis tortor ut augue lacinia, at viverra est semper. Sed sapien metus, tempor a tortor.
    <br />
    <br /> Pellentesque non dignissim neque. Ut porta viverra est, ut dignissim elit elementum ut.
  </div>
</div>

CSS

.affil2 {
  align-content: center;
  display: table;
  text-align: center;
  z-index: 20;
  border: 1px solid #705A1D;
  position: relative;
  height: 200px;
  width: 960px;
  background-color: #af9254;
  box-shadow: 0px 3px 10px 0px rgba(0, 0, 0, .35);
}

.contents {
  margin: 0 auto;
  text-align: left;
  width: 600px;
  display: table-cell;
  vertical-align: middle;
  color: #fff;
  font-size: 18px;
}

.oval2 {
  z-index: 1;
  position: absolute;
  top: -110px;
  width: 1200px;
  height: 250px;
  border-radius: 100%;
  background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.3) 0%, rgba(255, 0, 0, 0) 100%);
}

最佳答案

你的代码中有很多奇怪的东西,但是你可以改变你的解决方案:

width: 100%;text-align: center;contents

.contents {
  margin: 0 auto;
  text-align: center;
  width: 100%;
  display: table-cell;
  vertical-align: middle;
  color: #fff;
  font-size: 18px;
}

JsFiddle Link

关于html - 水平对齐表格内的表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44402063/

相关文章:

html - 宽度 <li> 根据高度适合内容 - IE/Chrome?

html - 强制 <div> 填充所有可用的垂直空间

CSS - 提交按钮显示短于文本输入

html - CSS Intellij 的自动完成 HTML 属性

html - 在 FireFox 中将边框宽度设置为 1px 时边框大小为 0.667

html - 使用 CSS 创建一个带有十字和文本的 div

html - 我有一个用伪元素制作的纯 CSS 工具提示,将内容作为属性,我如何添加链接到工具提示?

javascript - 仅在第一次单击按钮时增加计数器

php - 如何使用 jquery 在自动刷新 div 之前显示消息

css - Bootstrap 按钮与 Navbar 列表菜单对齐?