I have a passage that is centered on the page, like this:
_________________________
| |
| Once upon a time, there |
| lived a squirrel who |
| lived in the middle of |
| the forest. |
|_________________________|
I need to adjust the centering such that a specifically marked word is horizontally centered on the page. In this example, the word "who" is centered:
_________________________
| |
| Once upon |
| a time, there lived a |
| squirrel who lived in |
| the middle of the |
| forest. |
|_________________________|
- The word who is marked in the HTML with a
<div>
tag, i.e.<center>Once upon a time, there lived a squirrel <div style="centered">who</div> lived in the middle of the forest.</center>
. - The HTML appears in an application in which I have little control over editing the HTML itself (the text is already marked with CSS style tags), but can modify the style sheet or add code, such as JavaScript to the header to modify how that style is rendered.
How can I center a passage on a particular word in HTML, CSS, or JavaScript?
You can very simply do it in this way.
Fiddle Demo
Code:
Do you have a CSS file linked? If you do, I would recommend changing the div tag to
In the CSS file, you should have
It is also possible that you force the html to include spaces with the following code:   (Include a semicolon at the end, it won't let me do it). So instead of having one space, you can have multiple non-breaking spaces.
Use CSS more specifically in the parent elements to target your words alignment. For example if there is a paragraph (p) and then after it their are two divs (div) then use the specific parent css property like this.
that's it and it will do the work for you. Similarly you can target your given example with