html - 将表格与 div 垂直对齐

标签 html css

我有两个元素,一个表格和一个 div。

.LogoDiv {
  clear: both float: right;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
  filter: alpha(opacity=70);
  -moz-opacity: 0.7;
  -khtml-opacity: 0.7;
  opacity: 0.7;
  left: 500px;
  top: 100px;
  width: 200px;
  height: 300px;
  margin-top: 5%;
  margin-left: 85%;
  background-color: #003366;
}
.Logo {
  margin-top: 8%;
  margin-bottom: 8%;
  height: 84%;
  margin-left: 10%;
  margin-right: 10%;
  width: 80%;
}
.SubHeadTable {
  clear: both;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
  filter: alpha(opacity=70);
  -moz-opacity: 0.7;
  -khtml-opacity: 0.7;
  opacity: 0.7;
  margin-left: 15% margin-right: 15% margin-top: 20px;
  margin-bottom: 10px;
  background-color: #003366;
}
.SubHeadTitle {
  font-family: 'HurtMold', Fallback, sans-serif;
  color: #219c78;
  font-size: 28px;
}
.SubHeadText {
  font-family: 'Oregon', Fallback, sans-serif;
  color: 28a999;
  font-size: 18px;
}
.SubHeadTableRow {
  margin-top: 5px;
  margin-bottom: 5px;
  margin-right: 10px;
  margin-left: 10px;
}
.SubHeadTableCell {
  margin: 2px;
}
<table class="SubHeadTable">
  <tr class="SubHeadTableRow">
    <td class="SubHeadTableCell">
      <div class="SubHeadTitle">
        This is a title.
      </div>
      <br>
      <div class="SubHeadText">
        This is a text which relates to the title.
        <br>It explains the title further,
        <br>And could include various other elements.
        <br>
      </div>
    </td>
    <td class="SubHeadTableCell">
      <div class="SubHeadTitle">
        This is a title.
      </div>
      <br>
      <div class="SubHeadText">
        This is a text which relates to the title.
        <br>It explains the title further,
        <br>And could include various other elements.
        <br>
      </div>
    </td>
  </tr>
  <tr class="SubHeadTableRow">
    <td class="SubHeadTableCell">
      <div class="SubHeadTitle">
        This is a title.
      </div>
      <br>
      <div class="SubHeadText">
        This is a text which relates to the title.
        <br>It explains the title further,
        <br>And could include various other elements.
        <br>
      </div>
    </td>
    <td class="SubHeadTableCell">
      <div class="SubHeadTitle">
        This is a title.
      </div>
      <br>
      <div class="SubHeadText">
        This is a text which relates to the title.
        <br>It explains the title further,
        <br>And could include various other elements.
        <br>
      </div>
    </td>
  </tr>
</table>


<div class="LogoDiv">
  <img src="http://orig07.deviantart.net/312a/f/2010/241/c/3/my_logo_by_hamza_design-d2xjc1a.jpg" class="Logo">
</div>

我想将 div 和表格放在同一行,但我做不到。每当我在 HTML 中将一个放在另一个之前时,它会将另一个向下推,如下所示:

The situation

为什么会这样,如何让它们对齐?

最佳答案

在使用 display:inlinefloat:left 属性之前,元素 的样式 margin-left: 85%; .LogoDiv margin-left: 15% margin-right: 15% for .SubHeadTable 必须重新考虑。

根据 css,屏幕的总宽度不足以容纳这两个元素。这两个元素的 margin-left 占据了 100% 的屏幕。请查看 Box model在 CSS 中。

CSS 也有问题。

关于html - 将表格与 div 垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30766901/

相关文章:

javascript - 不注意数组长度条件的无限循环

html - 如何让 "display: table"的多个div单行显示

css - 使用 CSS 为表格自动编号

html - 在使用列的文本中添加图像

html - 如何在不使用 "polygon"的情况下获得三 Angular 形布局

html - 响应式 Google AdSense 已显示 :none, 但 HTML 仍然呈现相同?

html - 使用 CSS 将 <div> 左对齐到居中的 <div>

html - 背景图片未显示在 div 中

html - 带有视频背景的页眉,位置在 safari 中不起作用

html - 如何仅在换行符上添加边距?