chibineku Posted September 16, 2009 Report Share Posted September 16, 2009 I would like to output a few things very precisely. I want to display this - gross: £20.00P&P: £4.95total: £24.95but have the colons of the left hand words all line up vertically, and have the £ signs of the numbers line up vertically, so basically the fields need to be right aligned and the numbers left aligned. I am trying this using PHP's printf function, which at the moment looks like:<?php printf("%7s%-7s", "gross:","£$gross");?>$gross is a number that has been floatval() -ed. I have set the white-space attribute of the list item elements in which these values reside, but without <pre></pre> tags, it doesnt display right. with them, it still displays wrong. Here is the live example without pre tags:without pre tagsAnd here is one with:with pre tagsI have used printf to good effect before, but it is baffling me this time. Any help would be great. Link to comment Share on other sites More sharing options...
Synook Posted September 16, 2009 Report Share Posted September 16, 2009 Use a table. That's tabular data, anyway! Link to comment Share on other sites More sharing options...
chibineku Posted September 16, 2009 Author Report Share Posted September 16, 2009 (edited) Ha, you're right, it just feels wrong doing tables anymore... Edited September 16, 2009 by chibineku Link to comment Share on other sites More sharing options...
Synook Posted September 16, 2009 Report Share Posted September 16, 2009 it is wrong to use tables for non-tabular data. It is wrong not to use tables for tabular data. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2009 Report Share Posted September 16, 2009 You can also just float a couple divs, and align each one.<div style="width: 40px; text-align: right; float: left;">Gross:</div><div style="float: left; margin-left: 40px;">xxx</div><br style="clear: both;">I've used that style for various forms and things to get the labels to line up. Link to comment Share on other sites More sharing options...
chibineku Posted September 16, 2009 Author Report Share Posted September 16, 2009 True, I could do the div thing. I have used Synook's suggestion of a table already - it is tabular data, he's right, and it now lines up perfectly. I am also keen to make the site as accessible as possible and tables provide me with semantic elements that i can hide but which will be discoverable to screen readers so that users who browse differently know what's going on. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now