conceal the starting and ending markers for text separators

Here are two different methods to tackle this issue: one using pure CSS and the other utilizing jQuery. These solutions will allow for any symbol or image to be used as a separator.

Note: Creating and finding solutions for questions like these can be quite challenging, so I apologize if this has been addressed before.

I am dealing with a block of text that is multi-lined and justified, containing random (but not entirely) text hyperlink elements (such as tags or categories). These elements are separated by "|" symbols with spaces around them. This setup resembles a tag cloud but with fixed font-weight, size, and formatting. The problem arises when a separator is placed at the beginning or end of a line, which looks unattractive due to the nowrap setting on the link elements. I am looking for a solution to remove separators from the start and end of lines.

To better illustrate, let me provide an example:

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

The layout above demonstrates the issue. Each line should have content aligned to both sides without separators trailing off the ends. My goal is to achieve a structure similar to this:

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

Having a fixed number of elements in each line or enforcing a fixed width is not feasible in this scenario.

The only workaround I have thought of involves using monospace fonts and programmatically counting symbols to print line-by-line with server-side scripting. However, this approach comes with the downside of having to use monospace fonts. I am seeking a more elegant solution, such as implementing pure HTML/CSS (ideal) or formatting with JavaScript/jQuery after output.

Thank you for your assistance!

EDIT: In response to a comment below, the markup can be flexible and structured according to preference, something like:

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

Answer №1

Check out this cool concept: http://jsfiddle.net/WyeSz/
(please note that the jsfiddle demo includes a CSS reset, so you may need to add extra CSS for resetting list styles, etc.)

The idea is to apply border-left to the list items, and then shift the entire list -1px to the left within a container with overflow:hidden, which hides the left borders.

<div>
    <ul>
        <li>C++</li>
        <li>PHP</li>
        <li>CSS</li>
        <li>ASP</li>
        <li>JavaScript</li>
        <li>jQuery</li>
        <li>HTML 5</li>
        <li>StackOverflow</li>
    </ul>
</div>
ul {
    width:200px;  
    margin-left:-1px;/* hide the left borders */
}
li {
    float:left;   
    padding:2px 10px;
    border-left:1px solid #000;
}
div {
   overflow:hidden;/* hide the left borders */  
}

Answer №2

A solution to achieve this is by enclosing the | within a tag. Check out this example for reference.

Here is the code snippet:

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

For styling, use the following CSS:

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

To automate the process using JavaScript (jQuery), you can apply the following script:

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

Answer №3

Give this a shot:

Using jQuery:

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

In your HTML:

<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 method allows you to use any HTML content as your separator.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Accessing the camera or photo library in React Native does not require any permissions

In my current project, I am developing an app that requires users to upload images from their photo library or camera. To access the camera functionality, I am utilizing the react-native-image-picker library without integrating react-native-permissions. ...

The object THREE.DRACOLoader does not have a constructible function

When importing the three js and draco modules as shown below: import * as THREE from 'https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e7938f958282a7d7c9d6d5d6c9d6">[email protected]</ ...

Can a sophisticated text editor be utilized without a content management system?

Many website builders utilize rich text editors as plugins to enhance content creation, such as in CMS platforms like Joomla and WordPress. However, can these same editors be easily integrated into a custom website built from scratch using just HTML, PHP ...

Obtain the coordinates of the pixel in an image on the canvas when a mouse

I am currently working on a project that involves using canvas. I have set a picture as the background of the canvas and would like to be able to get the original pixel point when clicking in the image area. In order to achieve this, I need to convert canv ...

Do you know of any helpful resources for learning JSON with PHP through video tutorials?

I've been browsing the internet trying to learn about JSON, but a lot of tutorials are just too complicated for me. I'm specifically interested in learning how to use JSON with jQuery and PHP. If anyone has any recommendations for videos or websi ...

Experiencing difficulties typing into a text/input field using electron

I am currently working on a calendar app using electron. In the app, I have created a menu to add new events and other features. One feature I want to implement is allowing users to enter the title of their event in a textbox/input field. However, when I t ...

What is the best way to implement external routes.js files in order to avoid defining all routes within app.js?

Looking to create a basic link in Express? Follow these steps: a(href='/test', title='View test page') Test First, add a new file named test.js under the /routes directory with the following code: /* * GET test page. */ exports.test ...

Retrieve JSON data upon refreshing the page

In my blogging application, each post has its own unique permalink structure, such as /post/Dh3hdjs* where Dh3hdjs* represents the specific permalink. However, I am facing an issue where after successfully creating a post and being redirected to the specif ...

Error in Node.js: The res.send method is undefined

I'm having some issues with my first attempt at creating a simple Counter Strike API bot using nodeJS. The problem lies with the res.send function, as I keep getting an error message saying "res.send is not a function" every time I try to use it. Movi ...

Unable to establish the origin for an element using JavaScript

Currently, I am developing a simple game in JavaScript that includes a grid and various cells. Here is the current look of the game which functions perfectly. However, I am facing an issue with setting the margin to 0 and wanting to center the canvas inste ...

Utilizing Vue.js to pass a slot to a customized Bootstrap-Vue Table component

I am currently in the process of developing a wrapper for the bootstrap-vue Table component. This particular component utilizes slots to specify cell templates, similar to the following example: <b-table :items="itemsProvider" v-bind="options"> ...

Feature in ES6: map_iteration

I have been experimenting with the es6 map data structure, but I encountered an error when trying to iterate through the map. The specific error message is as follows: The error occurs on line 6: for (let [key, val] of m.entries()) SyntaxError: Unexpecte ...

Discovering feedback from JavaScript

I have been attempting to call JavaScript from a Visualforce page. The code snippet below shows a sample of the Visualforce page where I am trying to call a get method and am curious to see the response. Once I click on preview in the developer console, th ...

The function getObjectById is not functioning properly and is throwing an error: TypeError - scene.getObjectById is

Just starting out as a new programmer in the world of Javascript and three.js, I encountered an error where getObjectById is not working properly. The specific TypeError message reads: "scene.getObjectById is not a function." My goal was to access an obje ...

What is the best way to fetch the id of the option that has been chosen from a bootstrap drop-down menu?

I recently created a basic drop-down list like this: https://i.sstatic.net/4Tlxx.png Here is the HTML code for it: <select class="form-control" id='0' (change)="retrieveValue($event.target)"> <option id='0'>{{ g ...

When using @font-face, Chrome supports it while IE and Firefox do not

I am finding this quite perplexing. I am currently using font-squirrel to download a web kit in order to display a custom font. You can access the font through this link: If you visit the homepage now: The main text in the center reads "Custom Built Webs ...

Discovering the destination URL that an HTML button submits to

While attempting to scrape data from instacart.com, I encountered the requirement of entering a zip code to determine the displayed information. My intention is to utilize Python requests to submit a random zip code. However, I am unsure of which URL to po ...

Retrieve information from the API every second

In my React Native app, I have a system where customer orders are fetched and displayed on the restaurant side in a specific screen. I'm using the Fetch API to retrieve this data. The workflow is as follows: the customer places an order, which is then ...

The Django form isn't displaying properly after being imported into the HTML file

Can anyone help me figure out why my Django form isn't appearing in my HTML template? I've tried everything on this site and nothing seems to work. Any suggestions? views.py def handleForm(request): context = {} if request.method == &apo ...

Adding an image to a server through PHP in the TinyMCE editor

Currently, I am in the process of utilizing TinyMCE text editor for uploading images using PHP and JS database. However, I find myself perplexed when it comes to sending the image to the server. Below is the snippet of the JS code being used: <script ...