![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I'm mainly a coder, PHP at the moment, but from time to time need to design and use some css. I've a css text alignment issue. Mostly to align text neatly in the past I've used tables. But now I know I should be getting into the 21st C and using css properly. Here are 2 mock up pages with some forms on them, obviously I want the text boxes aligned neatly. The first page shows a nice alignment, the second does not, take a look. http://tinyurl.com/2ef9o5 http://tinyurl.com/27rf4e My form alignment uses 2 css entries: ItemLeft { position: relative; left: 10px; } ItemRight { position: relative; left: 75px; } To achieve the first page -the one neatly aligned- I used a fixed-width font (Courier New), and then added multiple entries so that the number of chars in the text on the left is the same, so that the alignment of the text boxes is neat. [...] Obviously this is a work-around which is rather amateurish and it does not work with non-fixed-width fonts. My instinct was to use a table, but this is exactly what css is supposed to stop. How do I get my alignment to work with non-fixed-width fonts, no forced spaces, and no tables? I just can't seem to find the right way to do this. |
#3
| |||
| |||
|
|
On 2007-11-28, Matthew <matt... (AT) spamkiller (DOT) com> wrote: Hi, I'm mainly a coder, PHP at the moment, but from time to time need to design and use some css. I've a css text alignment issue. Mostly to align text neatly in the past I've used tables. But now I know I should be getting into the 21st C and using css properly. Here are 2 mock up pages with some forms on them, obviously I want the text boxes aligned neatly. The first page shows a nice alignment, the second does not, take a look. http://tinyurl.com/2ef9o5 http://tinyurl.com/27rf4e My form alignment uses 2 css entries: ItemLeft { position: relative; left: 10px; } ItemRight { position: relative; left: 75px; } To achieve the first page -the one neatly aligned- I used a fixed-width font (Courier New), and then added multiple entries so that the number of chars in the text on the left is the same, so that the alignment of the text boxes is neat. [...] Obviously this is a work-around which is rather amateurish and it does not work with non-fixed-width fonts. My instinct was to use a table, but this is exactly what css is supposed to stop. How do I get my alignment to work with non-fixed-width fonts, no forced spaces, and no tables? I just can't seem to find the right way to do this. You could use floats. Something like this: .Label { float: left; clear: left; width: 10em; margin-left: 10px;} input { float: left; } ... form span class="Label">User:</span input type="text" name="user" span class="Label">Password:</span input type="text" name="password" /form Use margin-left on .Label, not position: relative, if you want to indent them a bit. To adjust the spacing between labels and text inputs, just change the width of .Label. So don't use position: relative at all. |
#4
| |||
| |||
|
|
On 2007-11-28, Matthew <matthew (AT) spamkiller (DOT) com> wrote: Hi, I'm mainly a coder, PHP at the moment, but from time to time need to design and use some css. I've a css text alignment issue. Mostly to align text neatly in the past I've used tables. But now I know I should be getting into the 21st C and using css properly. Here are 2 mock up pages with some forms on them, obviously I want the text boxes aligned neatly. The first page shows a nice alignment, the second does not, take a look. http://tinyurl.com/2ef9o5 http://tinyurl.com/27rf4e My form alignment uses 2 css entries: ItemLeft { position: relative; left: 10px; } ItemRight { position: relative; left: 75px; } To achieve the first page -the one neatly aligned- I used a fixed-width font (Courier New), and then added multiple entries so that the number of chars in the text on the left is the same, so that the alignment of the text boxes is neat. [...] Obviously this is a work-around which is rather amateurish and it does not work with non-fixed-width fonts. My instinct was to use a table, but this is exactly what css is supposed to stop. How do I get my alignment to work with non-fixed-width fonts, no forced spaces, and no tables? I just can't seem to find the right way to do this. You could use floats. Something like this: .Label { float: left; clear: left; width: 10em; margin-left: 10px; } input { float: left; } ... form span class="Label">User:</span input type="text" name="user" span class="Label">Password:</span input type="text" name="password" /form Use margin-left on .Label, not position: relative, if you want to indent them a bit. To adjust the spacing between labels and text inputs, just change the width of .Label. So don't use position: relative at all. |
#5
| |||
| |||
|
|
Ben C emailed this: On 2007-11-28, Matthew <matt... (AT) spamkiller (DOT) com> wrote: Hi, I'm mainly a coder, PHP at the moment, but from time to time need to design and use some css. I've a css text alignment issue. Mostly to align text neatly in the past I've used tables. But now I know I should be getting into the 21st C and using css properly. Here are 2 mock up pages with some forms on them, obviously I want the text boxes aligned neatly. The first page shows a nice alignment, the second does not, take a look. http://tinyurl.com/2ef9o5 http://tinyurl.com/27rf4e My form alignment uses 2 css entries: ItemLeft { position: relative; left: 10px; } ItemRight { position: relative; left: 75px; } To achieve the first page -the one neatly aligned- I used a fixed-width font (Courier New), and then added multiple entries so that the number of chars in the text on the left is the same, so that the alignment of the text boxes is neat. [...] Obviously this is a work-around which is rather amateurish and it does not work with non-fixed-width fonts. My instinct was to use a table, but this is exactly what css is supposed to stop. How do I get my alignment to work with non-fixed-width fonts, no forced spaces, and no tables? I just can't seem to find the right way to do this. You could use floats. Something like this: .Label { float: left; clear: left; width: 10em; margin-left: 10px; } input { float: left; } ... form span class="Label">User:</span input type="text" name="user" span class="Label">Password:</span input type="text" name="password" /form Use margin-left on .Label, not position: relative, if you want to indent them a bit. To adjust the spacing between labels and text inputs, just change the width of .Label. So don't use position: relative at all. Thanks very much for your help. That works very well. One question what is the purpose of the line... input { float: left; } ...it does not seem to make any difference to how the layout looks - I've tried it with that line in and out of the css file? Thanks again. |
#6
| |||
| |||
|
|
Hi, I'm mainly a coder, PHP at the moment, but from time to time need to design and use some css. I've a css text alignment issue. Mostly to align text neatly in the past I've used tables. But now I know I should be getting into the 21st C and using css properly. Here are 2 mock up pages with some forms on them, obviously I want the text boxes aligned neatly. The first page shows a nice alignment, the second does not, take a look. http://tinyurl.com/2ef9o5 http://tinyurl.com/27rf4e |
#7
| |||
| |||
|
|
"Matthew" <matthew (AT) spamkiller (DOT) com> wrote in message news:Ftg3j.54523$c_1.30740 (AT) text (DOT) news.blueyonder.co.uk... Hi, I'm mainly a coder, PHP at the moment, but from time to time need to design and use some css. I've a css text alignment issue. Mostly to align text neatly in the past I've used tables. But now I know I should be getting into the 21st C and using css properly. Here are 2 mock up pages with some forms on them, obviously I want the text boxes aligned neatly. The first page shows a nice alignment, the second does not, take a look. http://tinyurl.com/2ef9o5 http://tinyurl.com/27rf4e Some people would say that a form with labels *is* tabular data and that a table is therefore appropriate. |
#8
| |||
| |||
|
|
On Nov 28, 1:51 pm, Matthew <matt... (AT) spamkiller (DOT) com> wrote: Ben C emailed this: On 2007-11-28, Matthew <matt... (AT) spamkiller (DOT) com> wrote: Hi, I'm mainly a coder, PHP at the moment, but from time to time need to design and use some css. I've a css text alignment issue. Mostly to align text neatly in the past I've used tables. But now I know I should be getting into the 21st C and using css properly. Here are 2 mock up pages with some forms on them, obviously I want the text boxes aligned neatly. The first page shows a nice alignment, the second does not, take a look. http://tinyurl.com/2ef9o5 http://tinyurl.com/27rf4e My form alignment uses 2 css entries: ItemLeft { position: relative; left: 10px; } ItemRight { position: relative; left: 75px; } To achieve the first page -the one neatly aligned- I used a fixed-width font (Courier New), and then added multiple entries so that the number of chars in the text on the left is the same, so that the alignment of the text boxes is neat. [...] Obviously this is a work-around which is rather amateurish and it does not work with non-fixed-width fonts. My instinct was to use a table, but this is exactly what css is supposed to stop. How do I get my alignment to work with non-fixed-width fonts, no forced spaces, and no tables? I just can't seem to find the right way to do this. You could use floats. Something like this: .Label { float: left; clear: left; width: 10em; margin-left: 10px; } input { float: left; } ... form span class="Label">User:</span input type="text" name="user" span class="Label">Password:</span input type="text" name="password" /form Use margin-left on .Label, not position: relative, if you want to indent them a bit. To adjust the spacing between labels and text inputs, just change the width of .Label. So don't use position: relative at all. Thanks very much for your help. That works very well. One question what is the purpose of the line... input { float: left; } ...it does not seem to make any difference to how the layout looks - I've tried it with that line in and out of the css file? Thanks again. I think you were asking Ben C. but I may be able answer... Having "float:left" for two items next to each other should hopefully keep them on the same line next to one another I believe. I think it's somewhat optional in the case of form elements like the one's we've described above though. FWIW... I'm a PHP programmer primarily as well, having to learn to use CSS where I would have been using tables in the past, so I feel your pain. Luckily, I work with a designer who has more experience using CSS so I've picked up a lot. The A List Apart website has been pretty helpful too. |
#9
| |||
| |||
|
|
Nik Coughlin emailed this: "Matthew" <matthew (AT) spamkiller (DOT) com> wrote in message Some people would say that a form with labels *is* tabular data and that a table is therefore appropriate. ...but they would be wrong and have failed to understand what the term 'tabular data' means. :-) |
#10
| |||
| |||
|
|
Ben C emailed this: [...] You could use floats. Something like this: .Label { float: left; clear: left; width: 10em; margin-left: 10px; } input { float: left; } ... form span class="Label">User:</span input type="text" name="user" span class="Label">Password:</span input type="text" name="password" /form Use margin-left on .Label, not position: relative, if you want to indent them a bit. To adjust the spacing between labels and text inputs, just change the width of .Label. So don't use position: relative at all. Thanks very much for your help. That works very well. One question what is the purpose of the line... input { float: left; } ...it does not seem to make any difference to how the layout looks - I've tried it with that line in and out of the css file? |
![]() |
| Thread Tools | |
| Display Modes | |
| |