Jump to content

huge question about alignment


tomdelonge

Recommended Posts

i understand sufficiently how to create layouts for a website in css. now i have a huge problem. i use php, so i'll be "echoing" the sentences i need.

 

say i have two sentences. they both have a common word (which has been previously established in the php code). now how do you center the sentence on a word? (more specifically, the word should be centered, and the sentence surrounding it). so here's the example sentences:

 

i have an apple.

apple is a word that starts with the letter a.

 

apple in both sentences should be directly above each other. do you understand my question? if not, just let me know.

Link to comment
Share on other sites

If you were laying out a poem (some of which have their text laid out in a specific pattern) you would use {white-space:pre;} to preserve the white-space in the html source.

 

You should try that out. Apply that css to a specific paragraph where the source looks like:

 

this is an apple
             apple is good

Link to comment
Share on other sites

This is almost impossible. The only way it can be done is as the bronze monkey said, using a pre tag.

 

You will have to figure out a rule by which the words will need to be centered. If you do this, you will then have to use a font in which all letters have the same width. Then you can count out the number of spaces to output in order to place the word in the place you want.

 

 

 

Link to comment
Share on other sites

This is almost impossible. The only way it can be done is as the bronze monkey said, using a pre tag.

 

Don't even need to use a pre tag, just the css property-value of {white-space:pre;} on the element.

 

The only problem is that i don't know what the sentences are. (it's dynamic and always changing).

 

I can't see a reason to actually do this anyway.

 

But if you can think of some kind of robust logic in the nature of the sentences then you can always use php to do some calculations and write in the correct number of spaces before the repeated word on the second line to get it aligned. As haku said, you'll also need to make sure that the characters in the font are all the same width.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.