html - 如何在两个并排的 div 中垂直居中放置文本?

标签 html css

感谢阅读本文。

我有类似于下面的标记。当只有一行文本时使用行高有效,但评论数据通常是多行的。使标签和数据垂直居中的最佳方法是什么?

<html>
 <head>
 <style>
  body {margin:0; padding:0; font-size:12px; font-family:Verdana; text-align:center;}
  body {text-align: -moz-center; }  /* For Firefox */
  .record {width:760px; text-align:left; }
  .label {float:left; width:125px; line-height:75px;}
  .data {float:left; margin-left:10px; line-height:75px;}
  .clear {clear:left;}
 </style>
 </head>
 <body>
  <div class="record">
   <div class="label">Subject:</div>
   <div class="data">This is the subject</div>
   <span class="clear"></span>

   <div class="label">Status:</div>
   <div class="data">This is the status</div>
   <span class="clear"></span>

   <div class="label">Comments:</div>
   <div class="data">These are the comments</div>
   <span class="clear"></span>
  </div>
 </body>
</html>

最佳答案

http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

当然还有:

http://www.google.com/search?hl=en&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=vertically+align+text+div&spell=1

:)

table 有它们的位置;但最好在求助于表格之前尝试弄清楚如何在 div 中执行某些操作。这样,当您无法在表格中执行某项操作时,您会立即知道如何在 div 中执行该操作。此外 - 尽管它们可能比表格更复杂,但一旦您知道如何操作,它们就会在您的设计中提供更大的灵 active 。

关于html - 如何在两个并排的 div 中垂直居中放置文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/401996/

相关文章:

带有 HTML 联系表单的 PHPMailer

JQuery Mobile 1.4 文本输入宽度

css - Bootstrap 投资组合 - 空网格空间

javascript - 到 user_profile 的这条路由有什么问题?

javascript - 滚动对话框主体但不滚动其下方的页面

html - 为什么使用列表作为导航菜单?

javascript - 禁用/覆盖 Safari 中 popstate 事件的 anchor 跳转

javascript - 使用 Javascript 突出显示带有子菜单的当前页面链接

html - 跨度外的 form_for 图标

javascript - 空值和逻辑运算符不起作用