What is the method, by using JavaScript or CSS, to include extra space at the end of text block without starting a new line?

Imagine having some text, and at the conclusion of each paragraph there is a (more)... link. The layout ends up looking like this:

This is just an example paragraph. Click on the more link for additional information. (more...)

Now comes the desire to insert space between the link and the paragraph content, so the solution is to encase the link in a <span> element and adjust its position with a margin-left: 10px:

This is just an example paragraph. Click on the more link for additional information.     (more...)

The issue arises when the text wraps right after the 'more,' causing it to appear indented on a separate line:

This is just an example paragraph. Click on the more link for additional information. Continue reading!
     (more...)

The intended output should actually be:

This is just an example paragraph. Click on the more link for additional information. Continue reading!
(more...)

Can this effect be achieved using either Javascript or CSS?

Note: While it is feasible to achieve this outcome by eliminating the <span> tag and utilizing &nbsp characters to push the 'more' link to the right with correct text wrapping, this is an option that we prefer to avoid unless absolutely necessary. Alternatively, Javascript could be used to add the &nbsp's before the span, but this approach may not be ideal either.

Answer №1

To achieve this effect, you can specify a specific width for the paragraph and then use float to position the span on the right side.

This way, the (more...) text will always remain on the right side of the page.

While it may not be exactly what you're looking for, I believe it provides a decent appearance.

Here's an example: http://jsfiddle.net/WFuBd/1/

Answer №2

To achieve the desired effect, one technique is to enclose the content before the hyperlink in a span tag and set a margin-right on it. However, this may not be the most elegant solution available.

Answer №3

Have you considered using 2 divs for this? One div can float left while the other floats right. Make sure to set overflow=hidden on the left div, and place the "(more...)" content in the right div.

[Left div with lots of text, e.g. 300px] [Right div with "(more...)", e.g. 40px]

This approach will ensure a perfect layout every time. It may require some tweaking to get it just right, but it should work well. You could even add a little jQuery function to show the rest of the content and hide the 'more' when clicked.

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

Multiple charts experiencing disappearing x-axis labels on Flot

When trying to display two separate bar graphs, the x-axis labels seem to disappear. However, when only one graph is displayed, the labels show up perfectly fine. Any thoughts on why this might be happening? Here is the code snippet for displaying two gr ...

JavaScript not functional post AJAX request - navigating AJAX tabs

I am attempting to create a submenu that can update the page content without refreshing by using AJAX tabs to call an external HTML file. While the tabs are functioning properly, I am facing an issue with a JavaScript code within the external HTML file tha ...

When a JavaScript click event is triggered, IE8 can reset certain margins to zero

I am experiencing an issue with 3 divs containing content that becomes visible when clicking on 3 buttons. You can see a demonstration of the problem here: At times, when I click one of the buttons, the layout seems to be disrupted as shown here: It appe ...

Smoothly scroll through divs using JQuery

Let me share an issue I'm facing. I have implemented smoothDivScrolling on my webpage. The problem is that the scrollable area containing all the items to be scrolled always ends up being larger than the actual content. When I reach the last item i ...

What is the procedure for iterating through the square brackets of a JSON array?

Here's the data I have: $json_data_array = '[ { "id": 1, "value": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfd7cdffcbdacccb91dcd0d2">[email protected]</a>", ...

Alter the background color of the entire document to (EDIT) in the top dialog box

<script> $(function() { $( "#dialog" ).dialog(); }); </script> </head> <body> <div id="dialog" title="Basic dialog"> <p>This default dialog box can display information. It can be moved, re-sized, and closed ...

leveraging the power of JQuery and Ajax for submitting a form

I am looking to implement ajax functionality for form submission I want to achieve this using radio buttons instead of a submit button Essentially, when a radio button is clicked, the form should be submitted or posted My PHP page needs to determine whi ...

How can an object inside an array be destructured in just one line?

Consider the following array: const array = [{b:2}] Can you extract the value of b using destructuring in just one line? I attempted something similar to this approach, but it did not yield the desired result: const [{b} = array] ...

issues with conditional statement

I'm encountering an issue with the if statement not functioning as expected, and I can't seem to figure out why. The if condition always gets displayed regardless of the input. To troubleshoot, I initially used a temporary code snippet for the co ...

Dynamic Bootstrap Popover: Creating interactive popups by dynamically attaching events to buttons

I am looking to implement the Bootstrap Popover module to create a confirmation dialog for a delete action. When a <button> is clicked, instead of immediately executing a function, I want a popup to appear allowing the user to either confirm or dismi ...

Unable to locate the module name loaded using require() function

Within my React file, I am importing a Javascript file like this (I am using Typescript): let FloDialog = require('../public/js/flo-dialog.min'); Afterwards, I declare a property for the dialog class: dialog: FloDialog = null; It is important ...

Issue with jQuery .hover() not functioning as expected

The issue I'm encountering is just as described in the title. The code functions correctly on all divs except for one! $(".complete-wrapper-1").hide(); var panelHH = $(".file-select-wrapper").innerHeight; $(".files-button").hover(function(){ $(" ...

Struggling to pass command line arguments to index.ts with yarn?

My objective is to pass arguments through the command line using yarn start to index.ts. "scripts": { "start": "tsc-watch --onSuccess \"ts-node --pretty -r tsconfig-paths/register' src/index.ts\"", } When I attempt something like: yarn ...

Javascript generates a mapping of values contained within an array

In my current project, I am developing a feature that allows users to create customizable email templates with placeholder tags for content. These tags are structured like [FirstName] [LastName]. My goal is to brainstorm the most effective method for crea ...

Decoding multiple data with jQuery on the server-side

Scenario: A situation arises where I am utilizing a jQuery.ajax call to send three arrays to the server for database storage. The challenge lies in decoding the combined data object on the server side and breaking it back into the original three arrays. ...

Creating a div that becomes fixed at the top of the page after scrolling down a certain distance is a great way to improve user experience on a

I am struggling to create a fixed navigation bar that sticks to the top of the page after scrolling 500px, but without using position: fixed. Despite trying various solutions, none seem to work due to the unique layout of my navigation bar. Strangely enoug ...

Moving away from using Textarea, an alternative option is editable divisions. However, the issue arises when input

When using the following code: <div contentEditable="true" name="content"></div> instead of a Textarea in a form, I am unable to submit the input taken from the editable division above. The reason for using an editable division is to dynamic ...

utilizing symbols from a vector graphic icon库

There are countless icon images to be found on the internet. Recently, I came across this particular set and now I'm stumped on how to actually utilize them. Despite my efforts to find tutorials online, I have come up short in finding any helpful reso ...

The functionality of jQuery.hover with AJAX is malfunctioning

I am facing an issue with my jquery hover combined with $.post method. My initial intention was to create a series of select buttons where hovering would trigger a change in the image being displayed (the image path would be loaded via $.post). The image ...

The callback function in AngularJS filters

I'm currently using an AngularJS filter to sort through a list of items. Here is the Jade markup I am using: li(ng-repeat="parcel in parcels | filter : filterActiveAreaParcels") After the filter function runs and the elements are displayed in the DO ...