Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you do tab stops in HTML/CSS

There is some text whose formatting I would like to render in HTML. Here is an image:

Image of formatted text

Note the gray lines with the bullet points and the paragraph numbers. The bullets should be centered on the page and the numbers should be justified right.

I've been trying to think of how to do this in HTML and am coming up blank. How would you capture this formatting?

like image 412
Frank Krueger Avatar asked Jun 24 '11 19:06

Frank Krueger


People also ask

How do I make a tab stop in HTML?

Tab stops don't exist in HTML. You have to use tables (which is horrible) or use simple CSS. You can also use inch for declaring the 'tab stop' size p { padding-left: 2in; } if you like to. Or, and this is really just a joke, you can do it like Word.

How do I set the tab-size in CSS?

The tab-size CSS property is set the number of spaces each tab character will display. Changing this value allows inserting the needed amount of space on one tab character. This method however only works with pre-formatted text (using <pre> tags). The tab character can be inserted by holding the Alt and pressing 0 and 9 together.

Why are tab stops not supported in CSS?

Tab Stops for CSS. When it comes to converting documents created with word processors, HTML suffers from the lack of support for tab stops. Cumbersome work arounds can sometimes be found using HTML tables, but this abuses the value of markup and makes it harder for non-graphical user agents, e.g. for speech based browsers.

What is a tab in HTML?

TL;DR – In HTML, tab is a piece of whitespace equal to four HTML spaces in size. 1. Adding Tab Space in HTML 2. CSS Alternatives for HTML Tab 3. HTML Tab: Useful Tips Unlike with HTML space, there is no particular HTML tab character you could use. You could technically use the entity as the tab is character 9 in the ASCII.


1 Answers

You can use the :before and :after psuedo-elements to great effect here:

http://jsfiddle.net/yNnv4/1/

This will work in all modern browsers and IE8+. If IE7 support is required, this answer is not for you :)

#container {
    counter-reset: nums;
}
p {
    position: relative;
    margin: 21px 0;
}
p:before {
    content: '\2022 \2022';
    font-size: 2em;
    position: absolute;
    top: -8px;
    left: 0;
    line-height: 1px;
    color: #888;
    width: 100%;
    text-align: center
}
p:after {
    content: counter(nums);
    counter-increment: nums;
    font-size: 1.5em;
    position: absolute;
    top: -8px;
    right: 0;
    line-height: 1px;
    color: #888;
    font-family: sans-serif
}

About the counter properties:

  • https://developer.mozilla.org/en/CSS_Counters
  • http://www.w3.org/TR/CSS21/syndata.html#counter
  • http://www.w3.org/TR/CSS21/generate.html#propdef-counter-increment

It's not possible to (automatically) increment the bullets.

However, it can be done with some dubious repetition:

http://jsfiddle.net/N4txk/1/

p:before { content: '\2022' }
p+p:before { content: '\2022 \2022' }
p+p+p:before { content: '\2022 \2022 \2022' }
/* .... */

(alternatively, :nth-child can be repeated in the same way: http://jsfiddle.net/N4txk/ - but it won't work in IE8; there will only be two bullets)

There is an upper limit on the number of bullets it would be sensible to have, so I think it would be acceptable to copy and paste that as many times as required.

like image 156
thirtydot Avatar answered Oct 01 '22 21:10

thirtydot