tomdelonge Posted August 23, 2008 Share Posted August 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
bronzemonkey Posted August 23, 2008 Share Posted August 23, 2008 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 Quote Link to comment Share on other sites More sharing options...
tomdelonge Posted August 24, 2008 Author Share Posted August 24, 2008 the only problem is that i don't know what the sentences are. (it's dynamic and always changing). Quote Link to comment Share on other sites More sharing options...
haku Posted August 24, 2008 Share Posted August 24, 2008 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. Quote Link to comment Share on other sites More sharing options...
bronzemonkey Posted August 24, 2008 Share Posted August 24, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.