Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center some text and right-align more text on same line?

Tags:

css

I'm surprised that this has been so difficult for me. I need a single line with some text centered and the rest right-justified:

                          Centered Text                         Right Text

I doubt this matters, but "Centered Text" needs to be a <div> or <span> since I need to manipulate its content with jQuery. "Right Text" needs to be a <div> so I can apply styles to links it contains.

I've tried to float: left things, but I can't get it working. Any help would be appreciated.

like image 812
royco Avatar asked Dec 07 '22 05:12

royco


1 Answers

<div style="float: right">Right Text</div>
<div style="text-align: center">Centered Text</div>

The key is putting the floating element first.

like image 166
John Kugelman Avatar answered May 28 '23 19:05

John Kugelman