hide line beginning and end text separators

two solutions below: one with pure css, the second with jQuery, allowing any kind of symbol/image to be a separator

pre: Fairly hard to formulate and find such questions/solutions so I am sorry if duplicating.

I have a multi-line, justified block with random(not entirely) text hyperlink elements (tags/categories/etc) without fixed width separated by "|" symbol and spaces around. Looks pretty much like a tag cloud but with a fixed font-weight, size and other formatting, can contain more than one word in a hyperlink element. The problem rises when a separator is placed just before the end of the line or at the beginning of the line, actually, it happens always one way or another as I set nowrap to link elements, so this looks really ugly. Seeking for a solution to remove separators in the beginning and end of the lines.

For better understanding I will try to draw an example here.

C++ | PHP | CSS | ASP |
JavaScript | jQuery
| HTML 5 | StackOverflow

Something like that, of course, with justification and much more lines in a row. And another drawing of what I want to achieve.

C++ | PHP | CSS | ASP
JavaScript | jQuery
HTML 5 | StackOverflow

So fixed number of elements in a line is not an option, fixed width is also not an option.

The only solution I came up with is to set font to monospace and to count symbols and print pragmatically line-by-line with server-side scripting, the downside, of course, is the monospace fonts. Seeking for a better solution like pure html/css (would be perfect), JavaScript/jQuery formatting after output.

Thank you in advance!

EDIT: answering to a comment below, markup can be anything you wish, basically something like:

<div><a href="#">tag 1</a> | <a href="#">tag 2</a> | <a href="#">tag 3</a></div>



Here's an idea: http://jsfiddle.net/WyeSz/
(note that the jsfiddle demo uses a CSS reset, you may need a little more CSS than this to reset list styles, etc.)

Basically, you set border-left on the list items, then position the entire list -1px to the left within a container that has overflow:hidden, which cuts off the left borders.

        <li>HTML 5</li>
ul {
    margin-left:-1px;/* hide the left borders */
li {
    padding:2px 10px;
    border-left:1px solid #000;
div {
   overflow:hidden;/* hide the left borders */  

Yes you can do this but you need to put the | in a tag. Look at this example


<div id="tags">
    <a href="#">C++</a>
    <a href="#">PHP</a>
    <a href="#">ASP</a>
    <a href="#">JavaScript</a>
    <a href="#">jQuery</a>
    <a href="#">HTML 5</a>
    <a href="#">StackOverflow</a>


#tags {
    width: 170px;
#tags a {
    white-space: nowrap;

JavaScript (jQuery):

var iTop;
$("#tags a").each(function() {
    if (iTop < $(this).offset().top) {
    iTop = $(this).offset().top;

Try this:


$('document').ready(function() {
    $('div').find('a').not(':last-child').after(' | ');


<div><a href="#">tag 1</a><a href="#">tag 2</a><a href="#">tag 3</a></div>
<div><a href="#">tag 1</a><a href="#">tag 2</a><a href="#">tag 3</a></div>
<div><a href="#">tag 1</a><a href="#">tag 2</a><a href="#">tag 3</a></div>

This way, your content separator can be any HTML content.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.