0

This is not a duplicate as far as I can tell. The other cases don't answer my question because they only address centering an element, they don't have a block next to it (thus the "text-align: center" on a parent element won't help).

I have two text elements side by side, but I want one to be centered on the page and the other right next to it. The kicker is that the centered text is dynamic because it plugs in the user's name. So, I don't know how wide the text in the div is going to be.

If I make the text div inline-block or float: left it won't center. If I put both text divs into a container with text-align: center it will center both of them.

I just want one centered and the other next to it. Is such a thing possible?

Jonathan Grant
  • 143
  • 2
  • 15
  • 1
    Possible duplicate - http://stackoverflow.com/questions/7601678/is-it-possible-to-center-an-inline-block-element-and-if-so-how and http://stackoverflow.com/questions/4980525/css-center-display-inline-block – Luís P. A. Mar 20 '15 at 14:38
  • As I stated in the original question, the two elements need to be side by side, one centered and one not. Therefore, using align: center on a parent element won't work. – Jonathan Grant Mar 20 '15 at 15:59
  • Without seeing the HTML structure you propose using ut's hard to even have this re-opened. A child div could be positioned in relation to a centered parent but a sibling is much more problematical. – Paulie_D Mar 20 '15 at 16:09
  • As the question concerns adjacent elements relative to a centred element, this may not be a duplicate. – Flosculus Mar 20 '15 at 16:49

0 Answers0