Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting tab spaces to align text vertically in HTML/CSS

Tags:

html

css

I am not sure how to get the following behaviour using a combination of HTML and CSS:

foo    = this
foobar = bit
goso   = needs
etcetc = aligning

Now I could just insert spaces where required (like I did above), but I'm pretty sure there must be a way to do this "automatically".

I know I could use tables to do this, but would prefer not to. Is there any other way of doing this?

My question boils down to this: How do I automatically align text vertically, in a similar way to tabs in office suites, using HTML/CSS.

Here is an in context example:

<p><span class="a">foo</span> <span class="b">=</span> <span class="c">"abcDeveloper"</span></p>
<p><span class="a">bar</span> <span class="b">=</span> <span class="c">"123"</span></p>
<p><span class="a">foobar</span> <span class="b">=</span> <span class="c">"dfg"</span></p>
<p><span class="a">foobarstar</span> <span class="b">=</span> <span class="c">"456"</span></p>

In this example, I would like text in class b to be aligned vertically.

Thank you in advance!

like image 392
OMGtechy Avatar asked Nov 17 '13 22:11

OMGtechy


2 Answers

One method would be to apply display: inline-block; to your span.as, and then give them a set width: http://jsfiddle.net/nzrHn/1/

.a { display: inline-block; width: 100px; }
like image 157
Stuart Kershaw Avatar answered Sep 22 '22 19:09

Stuart Kershaw


Add css attribute display: inline-block and min-width: XXXpx

like image 44
codingpirate Avatar answered Sep 23 '22 19:09

codingpirate