The Urdu font is experiencing issues with its right-to-left direction functionality

When displaying Urdu text in an HTML tag (span), the text is supposed to be written from right to left. To achieve this, I added direction:rtl to the CSS styling. However, there seems to be an issue as on the last line, it leaves empty space on the right. Let me provide a clearer example.

.r2l {
  direction: rtl;
}
<html>

<head>
</head>

<body>
  <span class='r2l'>خدا کرے کے میری عرض پاک پے اترے</span>
  <span class='r2l'>وہ فصل گل جسے </span>
  <span class='r2l'>اندیشہ زوال نہ ہویہاں جو پھول کھلے کھلا رہےصدیوں یہاں 
  سے خزاں کو گزارنے کی مجال نہ ہو</span>
  <span class='r2l'>یہاں جو سبزہ اگے ہمیشہ سبز رہے</span>
  <span class='r2l'>اور ایسا سبز کے جسکیکوئی مثال نہ ہوخدا کرے کے نہ خام 
   ہو سر وقار وطن اور اس کے حسن کو تشوش ماہ وسا ل نہ ہو ہر ایک فرد ہو 
   تہذیب و فن کا</span>
  <span class='r2l'> اوج و کمال کوئی ملول نہ ہو کوئی خستہ حال نہ ہوخدا کرے 
     میرے ایک بھی ہم وطن کے لئےحیات جرم نہ ہو، زندگی وبال نہ ہو</span>
</body>

</html>

Upon running the snippet and observing the last line, you will notice that it does not align correctly from the right side but rather leaves empty space.

Edit The actual scenario includes adding different attributes to each span which are displayed when hovering over them. This helps in showing the attribution of the time the text was added to the database.

Answer №1

Right-to-left alignment does not function on <span> elements. For more details, refer to this link: Using <span> to add a direction (dir = "rtl")

Replace <span> and </span> with <p> and </p>

Answer №2

direction attribute is effective on block-level elements, but not on span.

Replace with the p tag instead.

.r2l {
  direction: rtl;
}
<html>

<head>
</head>

<body>
  <p class='r2l'>خدا کرے کے میری عرض پاک پے اترےوہ فصل گل جسے اندیشہ زوال نہ ہویہاں جو پھول کھلے کھلا رہےصدیوں یہاں سے خزاں کو گزارنے کی مجال نہ ہویہاں جو سبزہ اگے ہمیشہ سبز رہےاور ایسا سبز کے جسکیکوئی مثال نہ ہوخدا کرے کے نہ خام ہو سر وقار وطن اور اس کے حسن کو تشوش ماہ وسا ل نہ ہو ہر ایک فرد ہو تہذیب و فن کا اوج و کمال کوئی ملول نہ ہو کوئی خستہ حال نہ ہوخدا کرے میرے ایک بھی ہم وطن کے لئےحیات جرم نہ ہو، زندگی وبال نہ ہو</p>
</body>

</html>

Answer №3

To address the issue, I utilized the float:right property. While this solution did not fully meet my needs, it managed to work within my specific scenario.

.r2l {
  direction: rtl;
  float:right;
}
<html>

<head>
</head>

<body>
  <span class='r2l'>May God bless our land where my pure expressions flow</span>
  <span class='r2l'>The blooming season that does not witness any decline here as the flowers continue to bloom for centuries</span>
  <span class='r2l'>Where the grass grows always green</span>
  <span class='r2l'>And such a green for which there is no comparison May God preserve the dignity and beauty of the homeland so that neither desolation nor dimness may touch it Let every individual be an embodiment of culture and art without any boredom or weariness May none be fatigued May God grant even one like me life imprisonment for the country, may it never see trouble and distress in life </span>
</body>

</html>

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

Updating Github pages requires clearing the cache first

As I work on my first website using GitHub pages, I've noticed that it can be frustrating to constantly clear the cache or open an incognito window whenever I add something new. I'm thinking about incorporating Jekyll into my workflow so I can t ...

How can one execute a function within an HTML attribute value using Angular?

I am currently attempting to use the weatherToFontAwesomeIcon(weatherDescription: string) function directly within the HTML file for this component. My goal is to showcase a specific FontAwesome icon based on the weather response from the API. import { Cur ...

My code seems to be malfunctioning - why can't I keep the aspect ratio?

UPDATE: Can someone please assist me with maintaining the aspect ratio of a drawn image? I am struggling to achieve this and would appreciate any help. I have been attempting to upload an image, draw it using the imageDraw() function, and fit it within a ...

iOS image suddenly expands to full size after applying keyframe scale transformation

Encountering a peculiar iOS glitch while implementing CSS animations for moving shapes on a webpage. The issue arises when the shapes, initially displayed at full size, gradually shrink and fade out during animation. However, towards the end of the anima ...

Avoiding the use of "echo" in PHP can prevent unintended characters, especially the one created by the "¯

How can I prevent an issue where the '&macr' in a URL variable string creates the ¯ characters when echoed? echo "direct=1&closeBrowser=1&savelog=log.txt&storage=xfile&macrfile=klanta\test.html"; ...

Mastering the Art of Utilizing $(this) in jQuery

$(".item_listing").hover(function(){ $(".overlay_items").display(); },function(){ $(".overlay_items").hide(); } ); This is my jQuery code. I am trying to display the "overlay_items" div when the "item_listing" div is hovered ov ...

Issue with ng-bind-html not properly rendering content within audio tag

Currently, I am working with a variable called result.questionText. It currently holds the question: "<i>How many times are the hands of a clock </i>at right angle in a day?<audio controls ng-src="media/abc.mp3"></audio>". Instead o ...

Steps to access a unique custom drop-down menu in an upward direction

Presently, I am developing a customized AngularJS drop-down feature, which is outlined in the following HTML structure: <div> <label></label> <div> <a ng-class="{active: popover}"> <div></div> <!- ...

Utilize worldwide classes within CSS module

Currently, I am immersed in a project that makes use of ReactJS and CSS modules, where each React component is paired with a SASS file. During the CSS writing process, every class is suffixed with a 'triple underscore random string' like this: . ...

Store a designated text into a MySQL database by extracting it from every file within a directory

I've encountered various methods for "crawling" websites, but none seem to fit my requirements. I am interested in being able to extract data from each file within an online directory and then store the extracted information into a MySQL database: h ...

Modify HTML text using conditional CSS without JavaScript

Apologies for asking such a beginner question, but I've searched high and low for a similar post, to no avail. Here's my query: I have a paragraph text in my HTML code that I want to automatically replace with new text when I click a specific B ...

Activate search bar by clicking on it

I am currently attempting a basic jQuery example to expand a search bar on mouse click, but for some reason, my code is not working as expected. I have a simple jQuery function to display the input field when the button with the class "expand" is clicked, ...

Animation scaling on the iPhone seems to abruptly jump away once it finishes

Encountering an issue with animations that is causing unexpected behavior on physical iPhone devices but not in the simulators. The problem arises when the background zooms in and then the div suddenly jumps to the left after the animation completes, as sh ...

Utilizing jQuery for validating latitude and longitude coordinates with regular expressions

I implemented jQuery validation in the following way: $("#register-form").validate({ rules: { latitude: { required: true, strongCoord: true }, longitude: { required: true, strongCoord: true } }, messages: { yrAr: { required: &a ...

The scroll bar of the Bootstrap modal keeps playing peekaboo every time a new modal is triggered

After trying numerous solutions without success, I am posting this question regarding an issue with the scrolling behavior of Bootstrap modals. Here is the scenario: I have 2 Modals: Modal-1 and Modal-2. When a user is inputting information in Modal-1 ...

How to Make Bootstrap 3 Collapse Panels Stand Out with an Active Class

First of all, here is the fiddle link: http://jsfiddle.net/krish7878/h38jn324 I have a simple question. When a panel is clicked and it expands to show its contents, a class 'active' should be added to 'panel-heading'. I came across a ...

Creating a dynamic layout with Bootstrap 4 featuring a full-page design, two columns, and a

For a simple "login" page, I came across this template: HTML: <div class="d-flex align-items-center flex-column justify-content-center h-100 bg-dark text-white" id="header"> <h1 class="display-4">Hello.</h1 ...

How to position an absolute div in the center of an image both vertically and horizontally

Can someone help me figure out how to center a div inside an image? I seem to be having trouble with the positioning and alignment. Any suggestions or advice would be greatly appreciated. Thanks! .template-banner{ width: 100%; height: auto; margin: 0; } ...

I'm experiencing issues with my code involving HTML, CSS, and jQuery

Recently, I started learning about jQuery and came across a tutorial on creating a sticky nav bar. However, something went wrong during the implementation and now I don't know how to fix it! In my Script file, I have written code that should run on l ...

"Form submission fails to populate _POST when file and text fields are used simultaneously

Looking for a solution... <form action="upload.php" method="get" enctype="multipart/form-data"> Enter a 10 digit mobile number: &nbsp;<input id="imgphno" type="text" maxlength="10" /> <br/><br/> <input id="file" type="file" ...