When the direction is set to rtl, special characters that are supposed to be at the

When using the direction property for a label with windows style directory paths containing backslashes, I encountered an issue. The purpose of using direction:rtl; was to display the end part (file names) of the path. However, I found that I am getting the leading backslashes as trailing, which could confuse users. How can I prevent this from happening.

For reference, here is the link to the code snippet: http://jsfiddle.net/pguwo67m/2/

Currently, I am working on:


Additional Note

I have also observed that this issue occurs with other leading special characters. Fiddle: http://jsfiddle.net/6L1az99t/1/

Answer №1

Have you considered this method to shorten the path if it is too long:

NodeList.prototype.forEach = Array.prototype.forEach;

window.onload = function () {
    adjustWidths();
};

function adjustWidths() {
  // grab all label elements
  var labels = document.querySelectorAll('.path').forEach(function (lab) {
    var width = lab.getBoundingClientRect().width;
    if (width >= 260) {
      var path = lab.innerHTML;
      var pathArr = path.split("\");
      var newpath = pathArr[0] + '\...\ + pathArr[pathArr.length - 1];
      lab.title = path;
      lab.innerHTML = newpath;
    }
  });
}
#wrapper {
    width: 300px;
    border: 1px solid blue;
}
input {
    width: 20px;
}
<div id="wrapper">
    <div>
        <input type="checkbox" />
        <label class="path">development\productinfo.php</label>
        <div style="clear:both;"></div>
    </div>
    <div>
        <input type="checkbox" />
        <label class="path">development\application\models\cron\dropshipmodel.php</label>
        <div style="clear:both;"></div>
    </div>
    <div>
        <input type="checkbox" />
        <label class="path">develoment\application\controllers\cron\dropship.php</label>
    </div>
    <div>
        <input type="checkbox" />
        <label class="path">development\application\models\cron\dropshipmodel.php</label>
        <div style="clear:both;"></div>
    </div>
    <div>
        <input type="checkbox" />
        <label class="path">develoment\application\controllers\cron\dropship.php</label>
        <div style="clear:both;"></div>
    </div>
        <div>
        <input type="checkbox" />
        <label class="path">development\productinfo.php</label>
        <div style="clear:both;"></div>
    </div>
    <div>
        <input type="checkbox" />
        <label class="path">development\application\models\cron\dropshipmodel.php</label>
        <div style="clear:both;"></div>
    </div>
    <div>
        <input type="checkbox" />
        <label class="path">develoment\application\controllers\cron\dropship.php</label>
    </div>
</div>

Answer №2

Take a look at this.

Updates - 1. Insert text within span under label 2. Adjust width and format of the span element to block display.

That's all for now.

label {
    direction: rtl;
    float: left;
    overflow-x:hidden;
    white-space: nowrap;
}

label span{
width:150px !important;
display:block;
    
}

input {
    float: left;
}
<div>
    <input type="checkbox">
        <label class="editable"><span> \\\\development\productinfo.php</span></label>
    <div style="clear:both;"></div>
</div>
<div>
    <input type="checkbox">
    <label  class="editable"><span>\development\application\models\cron\dropshipmodel.php</span></label>
    <div style="clear:both;"></div>
</div>
<div>
    <input type="checkbox">
    <label  class="editable"><span>\develoment\application\controllers\cron\dropship.php</span></label>
    <div style="clear:both;"></div>
</div>
    <div>
    <input type="checkbox">
    <label  class="editable"><span>This is normal text, i want to display end part of a string</span></label>
    <div style="clear:both;"></div>
</div>

Thank you.

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

Measuring dimensions with HTML on the server - how to do it?

I am facing a challenge with my web application that allows users to upload entire .html files to the server. I am looking for a way to automatically detect and store the width/height of the uploaded html in my database. Currently, I have been experimenti ...

How to keep an image anchored at the bottom of the page without overlapping other content

I'm trying to have a logo image stay fixed at the bottom of a navigation drawer, but when I use absolute positioning and set it to the bottom, it overlaps with the list items on shorter devices. When the scroll bar appears due to shrinking the browser ...

A guide on switching out an HTML element with an AJAX response

How can I dynamically replace an HTML element with Ajax response? I know how to remove the element, but I'm unsure how to then insert the new content from the Ajax call. For instance, let's say I have the following code: <ul id="products"> ...

What is the mechanism behind YouTube automatically playing music videos when we visit a channel's homepage?

Since Chrome version 66, autoplay of videos with music has been restricted to muted playback. However, I recently noticed that on certain YouTube channel pages, the videos were autoplaying with sound, even when using the HTML video API. How is YouTube able ...

Is it wise to use the<sup>attribute for mandatory form fields?

Would it be wise to utilize the <sup> tag instead of using margin-top: -xnumberofpx for indicating required fields in a form? <label for="address1" required>Address line 1<sup><img src="/src/images/requiredAsterix.png" width="10" heig ...

What steps can I take to expand this on a grander level?

I have a code snippet for a personality quiz, but I'm facing an issue with increasing its size. Here's the HTML code: <h3>1. What is your favorite color?</h3> <input type="radio" name="q1" value="A" /> A. Red. <input type="r ...

I am in the process of troubleshooting why the header does not redirect correctly when clicked

As I work on developing a user authentication script for my database, I encounter an issue when trying to match the information in my MySQL database upon clicking a button. For some reason, nothing seems to happen regardless of whether the login informatio ...

Implement Bootstrap and CSS to ensure that my content appears below the header when users scroll down

I am struggling with a simple HTML page that is working well with CSS, but encountering an issue where the input form gets placed above the header when scrolling down. I want the header to always remain above the content even while scrolling. Any suggesti ...

Find the div element that wraps around the currently selected radio button

Take a look at this code snippet: <div class="paymentOption"> <input type="radio" name="paymentOption" value="1" /> <span class="marginLeft10">1-time payment using a different credit card</span> </div> Is it feasible ...

Developing tabbed sections in XSLT

Utilizing Angular JS within XSLT, I am aiming to develop a tab-based user interface using XML data. The requirement is to generate multiple links and corresponding div elements based on the number of nodes in the XML. To manage the display of these div ele ...

Why does the <div> element still have an offset even though its width and height are set to 100px and padding, margin, and border are set to 0px?

After styling my div element with specific CSS rules, I'm encountering an issue. The div has a set width and height of 100px along with padding, border, and margin all set to 0px. However, the elements are not being offset from the edges of the browse ...

Using Javascript to prevent css from changing the display

I want to make some CSS adjustments to a single element using a single script, but I want all the changes to be displayed at once. For example: $("#someelement").css({width:"100%"}); //this change should not be displayed $("#someelement").width($("#someel ...

Choosing from a dropdown menu by pressing keys

When I press the first letter of an option in my dropdown list, it works fine. However, if I try to press two, three, or four letters consecutively, the control vanishes. For example, if the option is 'Jquery' and I press J only, it works but pre ...

Issue with CSS 3 gradient compatibility in Internet Explorer 8

My CSS3 gradient button is working perfectly on all browsers except for IE8. To make it work on IE8, I am utilizing CSS3 Pie. You can see the search button in action by visiting: Upon inspecting my console, I noticed an error on this line: PIE.htc, lin ...

Access a folder in JavaScript using Flask

I need to specify a directory in a script. $images_dir = '{{url_for('.../pictures')}}'; In my flask application directory structure, it looks like this: Root -wep.py -templates -gallery.html -static -pictures The images are stored ...

sliderLighter: keep the slider moving smoothly at a constant speed

I am currently utilizing lightSlider and I want to create a continuous sliding effect with consistent speed. I do not want any stops or pauses between the images, just a smooth and constant movement. Is it possible to achieve this using lightSlider? Or per ...

Master the Art of Image Loading in Codeigniter

Hey there, I'm completely new to Codeigniter. In the Controllers folder, I've created a file called caller.php and in the \Views directory, I've created a file named home1.php. Additionally, within the root directory, I've made an ...

What causes the table to expand with new cells once the database information is shown?

I'm confused as to why an empty cell is being added to the right even if there is data from the database to display. This particular code is meant to showcase a school schedule. Attached is a picture showing how it currently appears. Below is the PH ...

What are the steps for distributing a styled React component?

My goal is to release a UI library using React, but I am struggling with how to handle styles. When I write code in a project, I typically use webpack and babel to build my code, resulting in the creation of a *.css file. import React from 'react&ap ...

Ways to eliminate the border color from bootstrap multiselect

I have been attempting to eliminate the border color surrounding options in a select box from Bootstrap Multiselect. Unfortunately, I am unable to identify the specific class responsible for adding the blue color around the option borders. This border app ...