0

I need the Invoice text to be left aligned and the Invoice # to be right aligned. I want them both to also be bottom aligned otherwise it looks odd with the an underline below. I have the following html:

<div style="height:75px; line-height:75px;">
    <div class="invoiceTitle">Invoice</div>
    <div class="invoiceNumber"># 12</div>
</div>

with the following CSS:

.invoiceTitle
{
    float: left;
    font-size: 36px;
    vertical-align: bottom;
}

.invoiceNumber
{
    float: right;
    font-size: 16px;
    vertical-align: bottom;
}

I can't figure out how to get them both aligned vertically together. There's extra code in there to show things I've tried unsuccessfully.

Stephane Grenier
  • 15,527
  • 38
  • 117
  • 192

2 Answers2

2

vertical-align: bottom; works only on inline blocks, whenever you used floats it moved to other Block formatting context. You can achieve that with flexbox & align-items: flex-end;

.container {
  height: 75px;
  display: flex;
  background-color: rgba(0, 0, 0, 0.1);
  align-items: flex-end;
}

.invoiceTitle {
  flex: 1;
  font-size: 36px;
}

.invoiceNumber {
  font-size: 16px;
  flex: 1;
  text-align: right;
}
<div class="container">
  <div class="invoiceTitle">Invoice</div>
  <div class="invoiceNumber"># 12</div>
</div>
felixmosh
  • 32,615
  • 9
  • 69
  • 88
1

I've made it with relative/absolute positioning I prefer using inline-block instead of float Scroll down to see

.container
{
    font-size: 36px;
    position:relative;
}
.invoiceTitle, .invoiceNumber{
   display:inline-block;
   position:absolute;
   bottom:0;
}
.invoiceNumber{
 right:0;
    font-size: 16px;
}
  <div class="container">
    <div class="container" style="height:750px; line-height:75px;">
        <div class="invoiceTitle">Invoice</div>
        <div class="invoiceNumber"># 12</div>
    </div
user10089632
  • 5,216
  • 1
  • 26
  • 34