Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can think of a CSS-only solution, but it only works if the preceding and succeeding text doesn't go over a line. You can find it at <a href="http://jsfiddle.net/2UQhC/5/" rel="nofollow">http://jsfiddle.net/2UQhC/5/</a> (you will need to hit 'run' to see it properly).</p> <p>The basic idea is this:</p> <ul> <li>There is a parent container with position: relative</li> <li>There is a para with the start of the sentence, and a para with the end of the sentence. Each contains a span at the start containing the pivot word.</li> <li>Both paras are put into place with position:absolute. The start has right: 50% (so it's right edge is in the middle) and the end has left:50% likewise.</li> <li>The spans in the paras are both floated towards the center.</li> <li>The spans are then given pseudo-elements with percentage based negative margins, that push their respective containers to the center. The percentage-based widths use the widths of the containing floats (not the line block), meaning that the basis for these percentage widths will always be the real width of laying out the pivot word in whatever font or font size you choose.</li> </ul> <p>Here's the code, in case that's too esoteric, using 'lilacs' as the pivot word:</p> <p>The HTML -</p> <pre><code>&lt;div&gt; &lt;p id="left"&gt;&lt;span&gt;LILACS&lt;/span&gt;April is the cruellest month, breeding&amp;nbsp;&lt;/p&gt; &lt;p id="right"&gt;&lt;span&gt;LILACS&lt;/span&gt;&amp;nbsp;out of the dead land&lt;/p&gt; &lt;/div&gt; </code></pre> <p>And the CSS -</p> <pre><code>div { position: relative; } #left { position: absolute; right: 50%; } #right { position: absolute; left: 50%; } #left span { float: right; } #right span { float: left; visibility: hidden; } #left span:after { content: ""; margin-right: -50%; } #right span:before { content: ""; margin-left: -50%; } </code></pre> <p>This will work whatever the widths of the two sides of the sentence (so long as they don't go to multiple lines), and should work from IE8 plus.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload