HighDots Forums  

Positioning a long line by a short spanned section

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss Positioning a long line by a short spanned section in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Samuel Murray
 
Posts: n/a

Default Positioning a long line by a short spanned section - 01-11-2008 , 11:30 AM






G'day everyone

Please tell me the following is possible using CSS positioning (it'll
make my day). I want to position a long line of text on the screen so
that a certain portion of it is in the middle of the screen. This
would be for a concordancer and we want to use HTML for the output.

I was initially thinking of doing this:

This is the <span style="position:center">house</span> that Jack
built.

But then "This is the that Jack built." is against the left margin
and only "house" is in the centre of the screen.

What I want is that "house" is in the centre of the screen, but the
rest of the text must hug it so that it displays the entire sentence
as a normal sentence (and the user must be able to select and copy it
as a normal sentence). If the sentence is too long on the left or the
right, it can go off-screen... that's okay.

Ultimately, this method will be used to display a long list of
sentences with the same words in the middle in a different colour, so
that users can easily see the words in context to determine how they
are used.

Please note that my CSS skills are very basic.

Any replies are appreciated.

Thanks
Samuel (aka voetleuce aka leuce)

Reply With Quote
  #2  
Old   
Ben C
 
Posts: n/a

Default Re: Positioning a long line by a short spanned section - 01-11-2008 , 04:28 PM






On 2008-01-11, Samuel Murray <leuce (AT) absamail (DOT) co.za> wrote:
Quote:
G'day everyone

Please tell me the following is possible using CSS positioning (it'll
make my day). I want to position a long line of text on the screen so
that a certain portion of it is in the middle of the screen. This
would be for a concordancer and we want to use HTML for the output.

I was initially thinking of doing this:

This is the <span style="position:center">house</span> that Jack
built.

But then "This is the that Jack built." is against the left margin
and only "house" is in the centre of the screen.

What I want is that "house" is in the centre of the screen, but the
rest of the text must hug it so that it displays the entire sentence
as a normal sentence (and the user must be able to select and copy it
as a normal sentence). If the sentence is too long on the left or the
right, it can go off-screen... that's okay.

Ultimately, this method will be used to display a long list of
sentences with the same words in the middle in a different colour, so
that users can easily see the words in context to determine how they
are used.

Please note that my CSS skills are very basic.
Here are two possible ways to do this, the first of which actually
appears to work reasonably acceptably in Firefox, Opera and Konqueror. I
doubt it will work in IE. Perhaps you will have more luck with the
second version in IE (although I doubt it). You might need to resort to
JS for IE. These solutions also require doing funny things with your
markup as you will see.

Anyway, here's one way to do it:

<style type="text/css">
.container
{
display: table;
margin: 0 auto;
padding: 0;
border-spacing: 0;
}
.special
{
position: relative;
display: block;
}
.special .left, .special .right
{
position: absolute;
top: 0;
white-space: nowrap;
width: 6000px; /* anything big */

/*
* It shouldn't be necessary to set width as well as
* white-space, but it makes a slight difference in Firefox
* to the position of the text in .left-- presumably the
* rightmost edge from the point of view of right text-align
* and from the point of view of shrink-to-fit width
* calculation work out slightly different in that browser
* for some reason.
*/
}
.special .left
{
right: 0;
text-align: right;
}
.special .right
{
left: 0;
text-align: left;
}
.hide { visibility: hidden }
</style>

...

<div class="container">
<span class="special">house
<span class="left">
This is the <span class="hide">house</span>
</span>
<span class="right">
<span class="hide">house</span> that Jack built.
</span>
</span>
</div>

Now for the second way, everything is the same except the first two
selectors:

.container { text-align: center }
.special
{
position: relative;

/*
* display: inline ought to work just as well here, according
* to CSS 2.1 specifications, but support for inline containing
* blocks in browsers is very poor. Support for display:
* inline-block is also poor, but better than it is for inline
* containing blocks.
*/
display: inline-block;
}


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.