嗨,我试着在同一行上创建spanh1元素。但是float:right将导致span移到顶部。我尝试了不同的方法,我不想使用保证金属性。有什么建议吗?

 <div class="block">
    <h1 class="pull-left">Carl</h1>
    <span class="pull-right">$4.81</span>
    <div style='clear:both'></div>
  </div>

CSS:
.pull-left{
  float:left;
  width:70%;
}
.pull-right:{
  float:right;
  width:20%;
}

任何帮助都将不胜感激。

最佳答案

这只是h1标记的默认边距,您需要删除它。
如果要根据h1垂直居中跨距,则只需使用行高:字体大小h1
Fiddle Here

<div class="block">
  <h1 class="pull-left">Carl</h1>
  <span class="pull-right">$4.81</span>
  <div style='clear:both'></div>
</div>

CSS如下
.block h1
{
  margin:0px;
}
.block span
{
  line-height:2em;
}
.pull-left{
  float:left;
  width:70%;
}
.pull-right:{
  float:right;
  width:20%;
}

10-05 20:41
查看更多