Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center text and float div to the right

Tags:

html

css

styles

I have a container div which has text within it that I want centered. I want to also insert a div into the container which floats to the right, like this:

<div id="container" style="text-align:center">
  Text
  <div id="child" style="float:right"></div>
</div>

Unfortunately what happens is that the text is no longer centered with respect to the container, but is instead shifted to the left by the width of the child.

Does anyone know how to get the text to center whilst keeping the div contained to the right?

like image 815
TheBoss Avatar asked Nov 10 '12 01:11

TheBoss


1 Answers

Something like this...

<div style='position:relative;'>
  my centered text
  <div style='position:absolute;right:0;top:0'>
    my right div
  </div>
</div>

You can obviously throw the inline styles into CSS.

like image 122
anson Avatar answered Nov 16 '22 18:11

anson