Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I vertical align text at top of div?

Tags:

html

css

How to align the <span> text at top of the <div> if float:right is applied to the <span>.

Here is my code:

span {
  float: right;
}
<div>Lorem ipsum dolor sit amet,
  <br>consectetuer adipiscing elit,
  <br> sed diam nonummy nibh dolore
  <span>Align me</span>
</div>

I tried vertical-align:text-top but its not working. I can't use negative margin and can't even make any changes to HTML.

like image 428
shubham agrawal Avatar asked Jan 19 '26 18:01

shubham agrawal


2 Answers

Please see this and let me know.

span {
  float: right;
  position: relative;
  bottom:40px;
}
like image 80
Dhaval Jardosh Avatar answered Jan 22 '26 09:01

Dhaval Jardosh


You can align it to the top right using position: absolute:

 p {
  position: relative;
 }

span {
  position: absolute;
  top: 0;
  right: 0;
}
<p>Lorem ipsum dolor sit amet, <br>consectetuer adipiscing elit,<br> sed diam nonummy nibh dolore <span>Align me</span></p>
like image 37
Ori Drori Avatar answered Jan 22 '26 10:01

Ori Drori



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!