I have a web page with two div sections, each with position:absolute (so I can put them just where I want them vertically) and a sentence of text. (This is a simplified case of the real page I am working on.)
I want the second sentence to be centered right-left in the width of the window, so it will adjust to stay centered if you change the window width.
However, as written, the text of the second sentence centers in the actual width of the first sentence, i.e., the width used, not the width available.
I get this (ignore the underscores):
<-------------------------- window width -------------------------->
This is the first sentence that I want to display.
___________________Center me.
when I wanted this:
<---------------------------- window width ----------------------->
This is the first sentence that I want to display.
_______________________________Center me.
Here's the code in question:
I haven't found a way to do what I want, despite reading CSS documentation and doing experiments with margin, width, border, and padding settings in the style.
What's the little secret I'm missing?
I want the second sentence to be centered right-left in the width of the window, so it will adjust to stay centered if you change the window width.
However, as written, the text of the second sentence centers in the actual width of the first sentence, i.e., the width used, not the width available.
I get this (ignore the underscores):
<-------------------------- window width -------------------------->
This is the first sentence that I want to display.
___________________Center me.
when I wanted this:
<---------------------------- window width ----------------------->
This is the first sentence that I want to display.
_______________________________Center me.
Here's the code in question:
Code:
<div style="position:absolute;top:50px">
This is the first sentence that I want to display.
</div>
<div style="position:absolute;top:150px">
<center>
Center me.
</center>
</div>
What's the little secret I'm missing?