0 votes
3.1k views
in Software Testing by (560 points)

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.       |
|_________________________|

 

 

  • 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?

1 Answer

0 votes
by (1.2k points)
[EDIT] Added fiddle. Cleaned up some code. Updated snippet below. Added comments.
 
[ORIGINAL] I don't believe that this is possible with css. However, I figured a solution could be possible with JavaScript. So, I tried it, and it worked! While this might not be the ultimate solution, consider the following:
 
<div class="jsCenterOnPhrase">
 
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the <div class="jsCenteredPhrase">lazy dog.</div>
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
The quick brown fox jumped over the lazy dog.
 
</div>
 
 

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated