css - 如何将 div 与其父级的顶部对齐但保持其内联 block 行为?

见:http://jsfiddle.net/b2BpB/1/

问:如何让box1和box3对齐到父divboxContainer的顶部?

#boxContainerContainer {
  background: #fdd;
  text-align: center;
}

#boxContainer {
  display: inline-block;
  border: thick dotted #060;
  margin: 0px auto 10px auto;
  text-align: left;
}

#box1 {
  width: 50px;
  height: 50px;
  background: #999;
  display: inline-block;
}

#box2 {
  width: 50px;
  height: 100px;
  background: #999;
  display: inline-block;
}

#box3 {
  width: 50px;
  height: 50px;
  background: #999;
  display: inline-block;
}

帮助非常感谢...

致谢:这个问题来自 https://stackoverflow.com/users/20578/paul-d-waite 之前给出的答案。 : Getting a CSS element to automatically resize to content width, and at the same time be centered

最佳答案

试试 vertical-align CSS 属性。

#box1 {
    width: 50px;
    height: 50px;
    background: #999;
    display: inline-block;
    vertical-align: top; /* here */
}

也将它应用到 #box3

https://stackoverflow.com/questions/5686276/

相关文章:

html - 在文本区域的占位符属性内插入换行符?

javascript - 在 HTML5 中使用目标 ="_blank"可以吗?

html - 删除vim中HTML标签之间的文本?

jquery - HTML5 textarea 占位符未出现

javascript - 单选按钮的 OnChange 事件处理程序(输入类型 ="radio")不

html - 我可以将 CSS 样式应用于元素名称吗?

jquery - Bootstrap 抛出 Uncaught Error : Bootstrap's

jquery - 使用 jQuery 获取所选选项的索引

css - iPad Safari 滚动会导致 HTML 元素消失并延迟重新出现

javascript - 加载网页时如何自动将焦点设置到文本框?