HTML div 对齐

标签 html css

我正在用 HTML 和 CSS 编写一个网站。对于页脚,我希望有两个对齐的“联系人”和“地址”框,其中联系人框的宽度为 25%,地址框的宽度为其余部分。不知何故,我的 div 无法正确对齐,地址框也无法与顶部垂直对齐。

我的尝试:

.footer {
  margin-top: 5px;
  width: 100%;
  border: 1px solid black;
}

.anschrift {
  width: 25%;
  padding: 5px;
  display: inline-block;
  border-right: 1px solid black;
  border-bottom: 1px solid black;
  vertical-align: top;
}

.kontakt {
  width: 70%;
  margin-left: 28%;
  display: inline-block;
  padding: 4px;
  vertical-align: top;
}
<div class="footer">
  <div class="anschrift">
    <h2>
      Anschrift:
    </h2>
    <h3>
      Lorem ipsum...
    </h3>
  </div>
  <div class="kontakt">
    <h2>
      Kontakt:
    </h2>
    <h3>
      Lorem ipsum...
    </h3>
  </div>
</div>

Screenshot

最佳答案

.footer {
  margin-top: 5px;
  width: 100%;
  border: 1px solid black;
}

.anschrift {
  width: 25%;
  padding: 5px;
  display: inline-block;
  border-right: 1px solid black;
  border-bottom: 1px solid black;
  vertical-align: top;
}

.kontakt {
  width: 70%;
  display: inline-block;
  padding: 4px;
  vertical-align: top;
  float:right;
}
<div class="footer">
  <div class="anschrift">
    <h2>
      Anschrift:
    </h2>
    <h3>
      Lorem ipsum...
    </h3>
  </div>
  <div class="kontakt">
    <h2>
      Kontakt:
    </h2>
    <h3>
      Lorem ipsum...
    </h3>
  </div>
</div>

.kontakt中删除左侧边距并将div向右浮动,即将.kontakt的代码更改为

.kontakt {
  width: 70%;
  display: inline-block;
  padding: 4px;
  vertical-align: top;
  float:right;
}

关于HTML div 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45106098/

相关文章:

Safari 忽略 CSS 颜色

php - 如何自动选择编辑表单中的值?

html - 不同语言的元标记

javascript - 如何在顶部显示导航栏的弹出窗口时保留和禁用 y 滚动条

jquery - Bootstrap 下拉崩溃,

javascript - 鼠标滚轮绑定(bind)上的 JQuery animate()

javascript - 改进代码 "content changer"

javascript - HTA 文档 GetElementById

javascript - 如何在 CSS 过渡中使用 ng-class?

CSS 媒体查询在 Firefox 和 Chrome 中不起作用