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
https://forums.phpfreaks.com/topic/121045-huge-question-about-alignment/
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

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.

 

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.