html - How to position a row of text based on a particular letter? -


i have line of text follow:

->a b c d e f g h j                   <- 

i want position line of text using css such letter d @ centre of page shown below:

->             b c d e f g h j      <- 

any idea?

if use monospaced font can use position:relative; , move row of text, since every letter , space has same size (demo). can achieve similar result on fonts without fixed-width, offset (left:;) little bit harder calculate, every letter occupies amount of horizontal space.

<nav class="letter monospace">     <div>a b c d e f g h j</div> <!-- monospaced font demo --> </nav> <nav class="letter">     <div>a b c d e f g h j</div> <!-- standard browser font demo --> </nav> <div id="leftmiddle"> </div> <div id="rightmiddle"> </div> 
nav.letter{     font-size:2em;     text-align:center; } nav.letter > div{ /* standard browser font */     position:relative;     left:1.05em; /* have calculate horizontal shift based on font you're using */ } nav.letter.monospace{     font-family:monospace; } nav.letter.monospace > div{ /* monospaced font */     position:relative;     left:1.75em; /* center row around 'e' change 0.75em, c 2.75em... */ }  nav ~ div{     width:49%;     min-height:200px;     height: 80%;     } #leftmiddle{ float:left;    border-right:1px solid;} #rightmiddle{    float:right;    border-left:1px solid;} 

html4 demo, working in ie7-9, ff10, opera, chrome.

update: see alternative demo (working in ie7-9, ff10, opera, chrome):

<div class="letter">     <div class="wrapper">         <div class="before">             b c         </div>         d                <div class="after">             e f g h j         </div>     </div> </div> 
.letter{     text-align:center;     overflow:hidden; } .letter > .wrapper{     width:1em;     margin:auto;     position:relative; } .letter > .wrapper > .before{     position:absolute;     right:125%;     text-align:right;     width:10em; } .letter > .wrapper > .after{     position:absolute;     text-align:left;     top:0;     left:125%;     width:20em; } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -