Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Float right moves the span element up?

Tags:

html

css

Hi i have beeen trying to make span and h1 element on the same line. However float:right will result span to move top. I have tried with different approach, i dont want to use margin property. Any sugesstions on this?

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

.pull-right: {
  float: right;
  width: 20%;
}
<div class="block">
  <h1 class="pull-left">Carl</h1>
  <span class="pull-right">$4.81</span>
  <div style='clear:both'></div>
</div>

Any help would be appreciated.

like image 725
divakar Avatar asked Jul 18 '26 14:07

divakar


2 Answers

Its just the default margin of h1 tag that is doing this, you need to remove that.

If you wanna vertically center the span based on h1 then just use line-height:font-size of h1

Fiddle Here

.block h1
    {
      margin:0px;
    }
    .block span
    {
      line-height:2em;
    }
    .pull-left{
      float:left;
      width:70%;
    }
    .pull-right:{
      float:right;
      width:20%;
    }
<div class="block">
  <h1 class="pull-left">Carl</h1>
  <span class="pull-right">$4.81</span>
  <div style='clear:both'></div>
</div>
like image 84
sani Avatar answered Jul 21 '26 05:07

sani


Use display inline css value:

<h1 class="pull-left" style="display:inline">Carl</h1>
<span class="pull-right" style="display:inline">$4.81</span>
like image 25
Hemã Vidal Avatar answered Jul 21 '26 04:07

Hemã Vidal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!