How to align a span to the right of the div with CSS?

Spread the love

Sometimes, we want to align a span to the right of the div with CSS.

In this article, we’ll look at how to align a span to the right of the div with CSS.

How to align a span to the right of the div with CSS?

To align a span to the right of the div with CSS, we use floats.

For instance, we write

<div class="title">
  <span class="name">Cumulative performance</span>
  <span class="date">20/02/2022</span>
</div>

to add nested divs.

Then we write

.title .date {
  float: right;
}

.title .name {
  float: left;
}

to make the span with class date move to the right with float: right;.

Conclusion

To align a span to the right of the div with CSS, we use floats.

Leave a Reply

Your email address will not be published. Required fields are marked *